Hi,
I have a macro and part of it involves copying a range of formulas and pasting it down rows while in a loop while updating a progress bar. When I am doing this row by row the macro works perfectly, but when I try to do it in batches of 10 rows the code works fine but when the macro gets to the next 'calculate' after this section of code excel crashes... basically whenever a calculate/save/calculation automatic code is found after this code finishes it crashes. Any ideas what I am doing wrong?? Examples below are firstly my line by line code which causes no issues, and then my batches of 10 code that causes the crash at any following calulate. Hope this makes sense... I am pretty new to VBA codeing.
:::working code:::
Dim KeyedDataRange As Long
Dim OriginalUsedDataRange As Long
Dim KeyedDataPostRemoval As Long
Dim RowProgress As Long
Dim CalcRowStart As Long
Dim CalcRowEnd As Long
Dim CurrentProgress As Double
Dim BarWidth As Long
Dim ProgressPercentage As Double
Dim CalcRowFinal As Long
RowProgress = 1
CalcRowStart = 4
CalcRowFinal = KeyedDataRange + 2
Call InitProgressBar
Do While CalcRowStart < CalcRowFinal + 1
Range("A2:L2").Select
Application.CutCopyMode = False
Selection.Copy
Range("A" & CalcRowStart & ":L" & CalcRowStart).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A" & CalcRowStart & ":L" & CalcRowStart).Calculate
CurrentProgress = RowProgress / (CalcRowFinal - 3)
BarWidth = Progress.Border.Width * CurrentProgress
ProgressPercentage = Round(CurrentProgress * 100, 0)
Progress.Bar.Width = BarWidth
Progress.Text.Caption = "STEP 1 of 2: Used Data Calculations - " & ProgressPercentage & "% Complete"
DoEvents
CalcRowStart = CalcRowStart + 1
RowProgress = RowProgress + 1
Loop
Unload Progress
:::code which causes excel crash on next calculate:::
Dim KeyedDataRange As Long
Dim OriginalUsedDataRange As Long
Dim KeyedDataPostRemoval As Long
Dim RowProgress As Long
Dim CalcRowStart As Long
Dim CalcRowEnd As Long
Dim CurrentProgress As Double
Dim BarWidth As Long
Dim ProgressPercentage As Double
Dim CalcRowFinal As Long
RowProgress = 1
CalcRowStart = 4
CalcRowEnd = 13
CalcRowFinal = KeyedDataRange + 2
Call InitProgressBar
Do While CalcRowStart < CalcRowFinal + 1
Range("A2:L2").Select
Application.CutCopyMode = False
Selection.Copy
Range("A" & CalcRowStart & ":L" & CalcRowEnd).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A" & CalcRowStart & ":L" & CalcRowEnd).Calculate
CurrentProgress = RowProgress / (CalcRowFinal - 3)
BarWidth = Progress.Border.Width * CurrentProgress
ProgressPercentage = Round(CurrentProgress * 100, 0)
Progress.Bar.Width = BarWidth
Progress.Text.Caption = "STEP 1 of 2: Used Data Calculations - " & ProgressPercentage & "% Complete"
DoEvents
CalcRowStart = CalcRowStart + 10
CalcRowEnd = CalcRowEnd + 10
RowProgress = RowProgress + 10
Loop
Unload Progress
I have a macro and part of it involves copying a range of formulas and pasting it down rows while in a loop while updating a progress bar. When I am doing this row by row the macro works perfectly, but when I try to do it in batches of 10 rows the code works fine but when the macro gets to the next 'calculate' after this section of code excel crashes... basically whenever a calculate/save/calculation automatic code is found after this code finishes it crashes. Any ideas what I am doing wrong?? Examples below are firstly my line by line code which causes no issues, and then my batches of 10 code that causes the crash at any following calulate. Hope this makes sense... I am pretty new to VBA codeing.
:::working code:::
Dim KeyedDataRange As Long
Dim OriginalUsedDataRange As Long
Dim KeyedDataPostRemoval As Long
Dim RowProgress As Long
Dim CalcRowStart As Long
Dim CalcRowEnd As Long
Dim CurrentProgress As Double
Dim BarWidth As Long
Dim ProgressPercentage As Double
Dim CalcRowFinal As Long
RowProgress = 1
CalcRowStart = 4
CalcRowFinal = KeyedDataRange + 2
Call InitProgressBar
Do While CalcRowStart < CalcRowFinal + 1
Range("A2:L2").Select
Application.CutCopyMode = False
Selection.Copy
Range("A" & CalcRowStart & ":L" & CalcRowStart).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A" & CalcRowStart & ":L" & CalcRowStart).Calculate
CurrentProgress = RowProgress / (CalcRowFinal - 3)
BarWidth = Progress.Border.Width * CurrentProgress
ProgressPercentage = Round(CurrentProgress * 100, 0)
Progress.Bar.Width = BarWidth
Progress.Text.Caption = "STEP 1 of 2: Used Data Calculations - " & ProgressPercentage & "% Complete"
DoEvents
CalcRowStart = CalcRowStart + 1
RowProgress = RowProgress + 1
Loop
Unload Progress
:::code which causes excel crash on next calculate:::
Dim KeyedDataRange As Long
Dim OriginalUsedDataRange As Long
Dim KeyedDataPostRemoval As Long
Dim RowProgress As Long
Dim CalcRowStart As Long
Dim CalcRowEnd As Long
Dim CurrentProgress As Double
Dim BarWidth As Long
Dim ProgressPercentage As Double
Dim CalcRowFinal As Long
RowProgress = 1
CalcRowStart = 4
CalcRowEnd = 13
CalcRowFinal = KeyedDataRange + 2
Call InitProgressBar
Do While CalcRowStart < CalcRowFinal + 1
Range("A2:L2").Select
Application.CutCopyMode = False
Selection.Copy
Range("A" & CalcRowStart & ":L" & CalcRowEnd).Select
Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Range("A" & CalcRowStart & ":L" & CalcRowEnd).Calculate
CurrentProgress = RowProgress / (CalcRowFinal - 3)
BarWidth = Progress.Border.Width * CurrentProgress
ProgressPercentage = Round(CurrentProgress * 100, 0)
Progress.Bar.Width = BarWidth
Progress.Text.Caption = "STEP 1 of 2: Used Data Calculations - " & ProgressPercentage & "% Complete"
DoEvents
CalcRowStart = CalcRowStart + 10
CalcRowEnd = CalcRowEnd + 10
RowProgress = RowProgress + 10
Loop
Unload Progress