Stuck Userform working with Worksheet

blacktour

Board Regular
Joined
May 24, 2005
Messages
219
I am close to getting this code to work but I get the most ridiculous sporadic errors and am getting frustrated. I have no idea why it freezes, sometimes it will give me errors like "End Sub", or Next x (random numbers), then the y=y + 31 is an error its never the same, then all of a sudden the code works find and does exactly what it is programed to do???

Anybody have any ideas. I am assuming I am missing something pretty important.

Private Sub cmdUpdate_Click()
Application.ScreenUpdating = False

Dim NumofTaxYr As Double
Dim TaxCalcSht As Worksheet
Dim y As Double
' Dim z As Double

Set TaxCalcSht = Worksheets("Tax Calc")
TaxCalcSht.Activate

NumofTaxYr = Val(cmbTaxYrEnd.Value) - Val(cmbTaxYrStart.Value) + 1

y = 10
' z = 0

For x = 1 To NumofTaxYr
TaxCalcSht.Rows(y & ":" & y + 29).Select
Selection.Copy

y = y + 31
' z = z + 1

TaxCalcSht.Rows(y & ":" & y).Select
ActiveSheet.Paste

' Cells(y + 1, 2).Value = cmbTaxYrStart.Value + z

Next x

TaxCalcSht.Range("A1").Select
Application.CutCopyMode = False
Unload Me
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
If I set a break point at Next X and keep clicking play and letting it break at next x it works every time, so I guess its something related to how the userform interacts with the worksheet? Not sure how to fix it.
 
Upvote 0
What is the actual error message, or is it just a 'code execution was halted' type message?
 
Upvote 0
I don't think it's an actual error then - it's a VBE glitch. See here for some options using Application.EnableCancelKey
There are also some discussions on this forum somewhere. ;)
 
Upvote 0
I don't think it's an actual error then - it's a VBE glitch. See here for some options using Application.EnableCancelKey
There are also some discussions on this forum somewhere. ;)

Thanks so much, it is working everytime I restarted excel and used this and its fine. I have been programming VBA on and off for quite a few years and haven't ran into this one yet lol.
Thanks again,
Mike
 
Upvote 0

Forum statistics

Threads
1,224,559
Messages
6,179,517
Members
452,921
Latest member
BBQKING

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