MrKowz
Well-known Member
- Joined
- Jun 30, 2008
- Messages
- 6,653
- Office Version
- 365
- 2016
- Platform
- Windows
Hey all,
I've been helping another user on the boards with some code, and something odd is happening. The code runs perfectly fine on my end, but when he runs it (on either of his computers. One is a quad core, the other is less in specs), his Excel freezes if he so much as MOVES the mouse. Both of us are using Excel 2003 (i'm even on a Citrix Thin Client!)
It is a relatively simple VBA procedure that incorporates screenupdating = false, enableevents = false, and manual calculation mode. I even incorporated a statusbar update at every loop, and he says that stops counting altogether.
Here is the code that, as I said, works perfectly fine on my end (I'm even using an identical copy of the worksheet this is meant to be ran on), but causes his computers to freeze.
I've been helping another user on the boards with some code, and something odd is happening. The code runs perfectly fine on my end, but when he runs it (on either of his computers. One is a quad core, the other is less in specs), his Excel freezes if he so much as MOVES the mouse. Both of us are using Excel 2003 (i'm even on a Citrix Thin Client!)
It is a relatively simple VBA procedure that incorporates screenupdating = false, enableevents = false, and manual calculation mode. I even incorporated a statusbar update at every loop, and he says that stops counting altogether.
Here is the code that, as I said, works perfectly fine on my end (I'm even using an identical copy of the worksheet this is meant to be ran on), but causes his computers to freeze.
Code:
Public Sub ReconcileHdrComm2()
Dim s As Long, _
d As Long, _
sLR As Long, _
dLR As Long, _
sWS As Worksheet, _
dWS As Worksheet
Set sWS = Sheets("Source")
Set dWS = Sheets("Sheet1")
sLR = sWS.Range("A" & Rows.Count).End(xlUp).Row
dLR = dWS.Range("A" & Rows.Count).End(xlUp).Row
With Application
.ScreenUpdating = False
.EnableEvents = False
.Calculation = xlCalculationManual
End With
If dLR < sLR Then
For s = 1 To sLR
For d = 1 To dLR 'Running this loop is significantly slower, but encompasses the entire sheet
Application.StatusBar = "Currently checking source row " & s & " versus destination row " & d & "."
If sWS.Cells(s, 12).Value = dWS.Cells(d, 12).Value And sWS.Cells(s, 9).Value <> dWS.Cells(d, 9).Value Then
If Left(sWS.Cells(s, 9).Value, InStr(sWS.Cells(s, 9).Value & "-", "-")) = dWS.Cells(d, 9).Value Then
dWS.Cells(d, 9).Value = sWS.Cells(s, 9).Value
dWS.Cells(d, 9).Interior.ColorIndex = 6
End If
End If
Next d
Next s
Else
For d = 1 To dLR
For s = 1 To sLR 'Running this loop is significantly slower, but encompasses the entire sheet
Application.StatusBar = "Currently checking source row " & s & " versus destination row " & d & "."
If sWS.Cells(s, 12).Value = dWS.Cells(d, 12).Value And sWS.Cells(s, 9).Value <> dWS.Cells(d, 9).Value Then
If Left(sWS.Cells(s, 9).Value, InStr(sWS.Cells(s, 9).Value & "-", "-")) = dWS.Cells(d, 9).Value Then
dWS.Cells(d, 9).Value = sWS.Cells(s, 9).Value
dWS.Cells(d, 9).Interior.ColorIndex = 6
End If
End If
Next s
Next d
End If
With Application
.ScreenUpdating = True
.EnableEvents = True
.Calculation = xlCalculationAutomatic
.StatusBar = False
End With