Visual Basic: Get row count of a sheet in Excel
On Mon, 6 Jul 2009 10:33:37 -0700 (PDT), Curious
wrote:
Thanks Lars-Åke! It works!
Now I've got another error, "Type mismatch" at the line marked below:
Sub MatchShortTermLimits()
myrowcount = Worksheets("LongTermLimits").UsedRange.Rows.Count
Sheets("LongTermLimits").Select
Dim r As Range, cell As Range
With ActiveSheet
Set r = .Range(.Cells(2, "D"), .Cells(myrowcount + 1, "D").End
(xlToLeft))
End With
i = 2
Do While i <= myrowcount + 1
If ActiveSheet.Cells("E", i).Value = "S" Then ' "Type
mismatch" error here
ActiveSheet.Cells("J", i).Value = Max(ActiveSheet.Cells
("D", i).Value, ActiveSheet.Cells("H", i).Value)
Else
If ActiveSheet.Cells("E", i).Value = "B" Then
ActiveSheet.Cells("J", i).Value = Min(ActiveSheet.Cells
("D", i).Value, ActiveSheet.Cells("H", i).Value)
End If
End If
i = i + 1
Loop
ActiveSheet.Save
End Sub
Anyone could again tell me what is wrong? Please help me!
You changed Cells(E,i) to Cells("E",i) but I think you should change
it to Cells(i,"E").
And the same for the other, similar, calls to Cells.
Hope this helps / Lars-Åke
|