Jared_Jones_23
New Member
- Joined
- Jun 24, 2011
- Messages
- 34
Hello,
I am relatively new to VBA and I have written a macro code that searches certain cells and then puts a formula into different cells that match the criteria. My macro is searching through thousands of cells and gets hung up and freezes whenever its run. Here the part of the code that is getting the error. If anyone has any suggestions I would appreciate it.
Thank You
Jared
Private Sub Workbook_Open()
Dim lastRow, lastCol As Long
Dim i, j As Integer
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
lastCol = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.count
lastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.count
count = 0
msg = "Work"
For i = 20 To lastRow
For j = 53 To lastCol
If Cells(i, j) <= Cells(17, j) And Cells(i, 14) >= Cells(18, j) Then
Cells(i, j) = (Cells(18, j) - Cells(17, j) + 1) / (Cells(i, 14) - Cells(i, 13) + 1) * Cells(i, 18) * Cells(i, 20)
End If
Next j
Next i
With Application
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub
I am relatively new to VBA and I have written a macro code that searches certain cells and then puts a formula into different cells that match the criteria. My macro is searching through thousands of cells and gets hung up and freezes whenever its run. Here the part of the code that is getting the error. If anyone has any suggestions I would appreciate it.
Thank You
Jared
Private Sub Workbook_Open()
Dim lastRow, lastCol As Long
Dim i, j As Integer
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
lastCol = ActiveSheet.UsedRange.Column - 1 + ActiveSheet.UsedRange.Columns.count
lastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.count
count = 0
msg = "Work"
For i = 20 To lastRow
For j = 53 To lastCol
If Cells(i, j) <= Cells(17, j) And Cells(i, 14) >= Cells(18, j) Then
Cells(i, j) = (Cells(18, j) - Cells(17, j) + 1) / (Cells(i, 14) - Cells(i, 13) + 1) * Cells(i, 18) * Cells(i, 20)
End If
Next j
Next i
With Application
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub