cssfonseca
New Member
- Joined
- Aug 14, 2018
- Messages
- 19
I'm trying to run a macro but now it keeps freezing excel. It runs with 10 cells, but when the macro is applied to almost two hundred, it freezes and crashes.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub eancheck()
Dim s1 As Worksheet, s2 As Worksheet
Dim Msg AsString
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet3")
Dim lr1 AsLong, lr2 AsLong
lr1 = s1.Range("A"& Rows.Count).End(xlUp).Row
lr2 = s2.Range("a"& Rows.Count).End(xlUp).Row
Dim i AsLong, j AsLong
Application.ScreenUpdating =False
For i =2To lr1
s1.Cells(i,"D").Interior.ColorIndex =0
For j =2To lr2
If s2.Range("A"& j)= s1.Range("D"& i)Then
's1.Range("D" & i) = s2.Range("B" & j)
s1.Cells(i,"D").Interior.ColorIndex =3
EndIf
Next j
Next i
Application.ScreenUpdating =True
EndSub
</code>I'm having problems with other macros too, and I think is because of the size of the range. How can I fix it?
Note: The macro runs when searching 10 values in a sheet with two columns with almost 200.000 values each, but when instead of 10 is 200, crashes.
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Sub eancheck()
Dim s1 As Worksheet, s2 As Worksheet
Dim Msg AsString
Set s1 = Sheets("Sheet1")
Set s2 = Sheets("Sheet3")
Dim lr1 AsLong, lr2 AsLong
lr1 = s1.Range("A"& Rows.Count).End(xlUp).Row
lr2 = s2.Range("a"& Rows.Count).End(xlUp).Row
Dim i AsLong, j AsLong
Application.ScreenUpdating =False
For i =2To lr1
s1.Cells(i,"D").Interior.ColorIndex =0
For j =2To lr2
If s2.Range("A"& j)= s1.Range("D"& i)Then
's1.Range("D" & i) = s2.Range("B" & j)
s1.Cells(i,"D").Interior.ColorIndex =3
EndIf
Next j
Next i
Application.ScreenUpdating =True
EndSub
</code>I'm having problems with other macros too, and I think is because of the size of the range. How can I fix it?
Note: The macro runs when searching 10 values in a sheet with two columns with almost 200.000 values each, but when instead of 10 is 200, crashes.
Last edited: