Type mismatch when selecting a row using a variable for the row

Type mismatch when selecting a row using a variable for the row

Post by Jim Sabado » Sat, 14 Apr 2001 21:04:02



Hi all,
In the following Sub, I get a type mismatch in the line "
Rows("rw:rw").Select ".  I would have thought that if the rw variable (as an
integer) worked for the Cells object it should have worked for the rows
object.  When I hold my cursor over the rw in the previous line it says "rw
=15" so I don't understand why I am getting the type mismatch.  What am I
doing wrong?
Thanks for the continued help!
Jim

Sub DeleteIMsg()
Dim rw As Integer
For rw = 1 To 32767
If Cells(rw, 8).Value = "" Then Exit Sub
 If Cells(rw, 8).Value = "I" Then
     If Cells(rw, 9).Value = "NI" Then
       Rows("rw:rw").Select
       Selection.Delete shift:=xlUp
     End If
  End If
Next rw
End Sub

 
 
 

Type mismatch when selecting a row using a variable for the row

Post by Bob Flanaga » Sat, 14 Apr 2001 21:34:47


Jim, because you enclose rw in quotes, "rw:rw", you are telling VB to use
the test string rw instead of the variable value of rw.  If you did this:
Rows(rw:rw), it still would not work because of the colon not being enclosed
in quotes.  This may work:  rows(rw & ":" & rw), but the simple way is
rows(rw).

Also, you are deleting top down.  This means that if rw is 10 and you delete
row 10, that row 11 became row 10 and doesn't get tested.  Instead, delete
from the bottom up by changing your For statement to:  For rw = 32767 to 1
step -1  And, you don't have to select a row to delete it. Use
Rows(rw).Delete.

Hope this helps,

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


Quote:> Hi all,
> In the following Sub, I get a type mismatch in the line "
> Rows("rw:rw").Select ".  I would have thought that if the rw variable (as
an
> integer) worked for the Cells object it should have worked for the rows
> object.  When I hold my cursor over the rw in the previous line it says
"rw
> =15" so I don't understand why I am getting the type mismatch.  What am I
> doing wrong?
> Thanks for the continued help!
> Jim

> Sub DeleteIMsg()
> Dim rw As Integer
> For rw = 1 To 32767
> If Cells(rw, 8).Value = "" Then Exit Sub
>  If Cells(rw, 8).Value = "I" Then
>      If Cells(rw, 9).Value = "NI" Then
>        Rows("rw:rw").Select
>        Selection.Delete shift:=xlUp
>      End If
>   End If
> Next rw
> End Sub


 
 
 

Type mismatch when selecting a row using a variable for the row

Post by Jim Sabado » Sun, 15 Apr 2001 02:46:31


Bob,
Thanks for the quick response and great explanation.  It worked perfect!
Jim
 
 
 

1. selecting rows using a variable

Hey,
I am trying to write a macro that will select a certain number of rows
based on the value of a cell.  For example, suppose I want to select
rows 6 through 10; I write

Rows("6:10").Select

My problem is that I cannot get the syntax correct to tell Excel 7.0 to
select rows 6 through x, when x is the value in cell B6.  If I write

Rows("6:x").Select

I get an error message.  I have tried to use a Dim statement but that
failed too.  If anyone can help me, I would greatly appreciate it.

Thanks in advance,

Steve

2. strcasecmp() not available for Mac in MSL?

3. Getting row data from a selected row?

4. won't remember passwords, etc.

5. Multiple rows in table but display single row in select statement

6. Netware Client Installation Error

7. Selecting Rows by Variable Name

8. Does the 3850/70 comes with USB cradle as standard?

9. selecting variable rows based on countif

10. graphing selected (and variable) rows

11. Selecting random rows using weights

12. Using INDEX on date/time values // Re: how to select a time frame on timestamp rows.

13. Using ROW types