View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Curious[_2_] Curious[_2_] is offline
external usenet poster
 
Posts: 23
Default Visual Basic: Get row count of a sheet in Excel

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!