-
Yea, you will have to use the form name instead of Me. If you are searching a lot, and if each search takes a few seconds or more, it is going to take a while.
There are some things that may speed it up. Insead of writing to each cell in the loop, build a range and write one time.
For example
[vba]
Worksheets("MySearch").Range("B8").Offset(i, 0).Value = "Whatever"
[/vba]
Change To
[vba]
If MyRange Is Nothing Then
Set MyRange = Worksheets("MySearch").Range("B8").Offset(i, 0)
Else
Set MyRange = Union(MyRange, _
Worksheets("MySearch").Range("B8").Offset(i, 0))
End If
[/vba]
Then at the end of the loop just change the value of MyRange.
[vba]
MyRange.Value = "Whatever"
[/vba]
Also make sure that there are no events triggering when you are changing the cells. You should start the macro with.
[vba]
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.ScreenUpdating = False
[/vba]
And set them back to True at the end of your code. Application.ScreenUpdating = False could speed it up considerable, or maybe not. Depending on what is slowing you down. But it will be faster.
If you have a lot of formulas, turn calculations to manual at the start of you code and back to automatic at the end.
[vba]Application.Calculation = xlCalculationManual
Application.Calculation = xlCalculationAutomatic[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules