I have a macro that went from running in 1-2 minutes in 2003 to taking 35-40 minutes in 2010. I have been trying to figure out what is causing the slow down. I think I have narrorwed it to this section of code.
Public Property Get StartRow(sheetName, TextValue, Optional theOccurrence As Integer)
Dim Count As Integer
Set c = Sheets(sheetName).Cells.Find(What:=TextValue, After:=Selection.SpecialCells(xlCellTypeLastCell), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
Count = theOccurrence
Do Until Count < 2
Set c = Cells.FindNext(After:=Cells(c.Row, c.Column))
Count = Count - 1
Loop
If c Is Nothing Then
theStartRow = "Nothing"
Else
theStartRow = c.Row
End If
Set c = Nothing
StartRow = theStartRow
End Property
Public Property Get EndRow(sheetName, TextValue, Optional theOccurrence As Integer)
Set c = Sheets(sheetName).Cells.Find(What:=TextValue, After:=Selection.SpecialCells(xlCellTypeLastCell), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
Count = theOccurrence
Do Until Count < 2
Set c = Cells.FindNext(After:=Cells(c.Row, c.Column))
Count = Count - 1
Loop
If c Is Nothing Then
theEndRow = "Nothing"
Else
i = c.Row
j = c.Column
Do
i = i + 1
Loop Until Sheets(sheetName).Cells(i, j) = ""
theEndRow = i - 1
End If
Set c = Nothing
EndRow = theEndRow
End Property
I have similar code to get the StartCol and EndCol. Does anyone have a more efficent way to get the begining and ending row and column of the data on the sheet?
Thanks,
kcsmiles
Public Property Get StartRow(sheetName, TextValue, Optional theOccurrence As Integer)
Dim Count As Integer
Set c = Sheets(sheetName).Cells.Find(What:=TextValue, After:=Selection.SpecialCells(xlCellTypeLastCell), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
Count = theOccurrence
Do Until Count < 2
Set c = Cells.FindNext(After:=Cells(c.Row, c.Column))
Count = Count - 1
Loop
If c Is Nothing Then
theStartRow = "Nothing"
Else
theStartRow = c.Row
End If
Set c = Nothing
StartRow = theStartRow
End Property
Public Property Get EndRow(sheetName, TextValue, Optional theOccurrence As Integer)
Set c = Sheets(sheetName).Cells.Find(What:=TextValue, After:=Selection.SpecialCells(xlCellTypeLastCell), _
LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
Count = theOccurrence
Do Until Count < 2
Set c = Cells.FindNext(After:=Cells(c.Row, c.Column))
Count = Count - 1
Loop
If c Is Nothing Then
theEndRow = "Nothing"
Else
i = c.Row
j = c.Column
Do
i = i + 1
Loop Until Sheets(sheetName).Cells(i, j) = ""
theEndRow = i - 1
End If
Set c = Nothing
EndRow = theEndRow
End Property
I have similar code to get the StartCol and EndCol. Does anyone have a more efficent way to get the begining and ending row and column of the data on the sheet?
Thanks,
kcsmiles