Type Mismatch.

  • Thread starter Thread starter mika.
  • Start date Start date
M

mika.

Hello, can anyone enligten me as to why the code below
gives me an error 13: type mismatch? Thanks so much.

Dim row
Dim col
Dim allblank As Boolean

For Each row In ballotWkst.Rows
allblank = True
For Each col In ballotWkst.Rows(row).Columns '<--line
it doesn't like
'code
Next
next
 
Hi,



In your code "row" is not an integer but represent a range. Add a integer
that you will increment each time it do the loop and use this number to get
into the column.
 
One way around it:

Option Explicit
Sub testme02()

Dim myRow As Range
Dim myCell As Range

Dim allBlank As Boolean

For Each myRow In ballotWkst.UsedRange.Rows
allBlank = True
For Each myCell In myRow.Cells
'code
Next
Next

End Sub

I don't like using variables that are reserved words. And since you're dropping
through the rows, then each Column (of that row) is just a cell.

It looks like you want to do something to each row that's completely empty
(delete it???). If you are deleting them, it's a lot easier to start from the
bottom and work your way up. (You'll have a lot less to take care of):

Option Explicit
Sub testme02a()

Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long

With ballotWkst
FirstRow = 1 '????
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).row

For iRow = LastRow To FirstRow Step -1
If Application.CountA(.Rows(iRow)) = 0 Then
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub
 
Back
Top