What's wrong with my code? (cells reference and calculations)

billatosu

New Member
Joined
Oct 27, 2013
Messages
5
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
 
ActiveSheet is NOT explicit.
It's actually a variable, it depends on which sheet is currently active.

However, the activesheet may not actually be what you think it is.

To be explicit, actually Name the sheet as I did in the example.
This way there is no doubt which sheet you are referring to.
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top