Hi, the following code runs OK from within a simple macro. But when run triggered from a command button click, it hangs at the line in Bold font below. Can anyone tell me what is wrong? The purpose of this code is to replace certain rows (row 16 until last row) of each column with a new date value. It also has a progress bar. Thank you!
For n = 1 To Round(LastColumn / 2)
Columns(2 * n - 1).Select
LastRow = Cells.Find(What:="*", After:=Range("A1"), SearchOrder:= _
xlByRows, SearchDirection:=xlPrevious).Row
For i = 16 To LastRow - 1
Cells(i, 2 * (n - 1) + 1) = Cells(10, 2 * (n - 1) + 2) _
+ (i - 16) * Cells(13, 2 * (n - 1) + 2) / 24 / 60 / 60
Next
If LastRow > MaxRow Then
MaxRow = LastRow
End If
PctDone = n / LastColumn
With UserForm1
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents
Next
For n = 1 To Round(LastColumn / 2)
Columns(2 * n - 1).Select
LastRow = Cells.Find(What:="*", After:=Range("A1"), SearchOrder:= _
xlByRows, SearchDirection:=xlPrevious).Row
For i = 16 To LastRow - 1
Cells(i, 2 * (n - 1) + 1) = Cells(10, 2 * (n - 1) + 2) _
+ (i - 16) * Cells(13, 2 * (n - 1) + 2) / 24 / 60 / 60
Next
If LastRow > MaxRow Then
MaxRow = LastRow
End If
PctDone = n / LastColumn
With UserForm1
.FrameProgress.Caption = Format(PctDone, "0%")
.LabelProgress.Width = PctDone * (.FrameProgress.Width - 10)
End With
DoEvents
Next