Sheet functions using a macro on a user form...

GS7CLW

Banned
Joined
Aug 10, 2010
Messages
168
It'sssssssssssssssssssss FRiiiiiday!!!!!!!!!!!!!!!!!!!!

I have a userform2 with this macro on it:

Code:
Private Sub ClearMstrBtn_Click()
'-----------clear master sheet-----------
With Sheet("Mast")
Dim LastNameRow
LastNameRow = Range("A" & Rows.Count).End(xlUp).Row
Range("A2:AB" & LastNameRow).Select
Selection.ClearContents
Range("A2").Select
End With
End Sub

BUuuuuuT, when I run it I get a Sub or function not defined.


Annnnny help would be GREATLY appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
always enforce variable declaration, by adding "option explicit" to the top of your code modules. In VBA > tools > options you can select a tick box that does this automatically. Doing so should highlight the error to you at run time

in your "With" construct, you have rows.count that hasn't been qualified, i.e. it should be .rows.count

You don't need to "select" the data, just refer to it without the selections

Code:
Dim LastNameRow as long
With Sheet("Mast")
    LastNameRow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("A2:AB" & LastNameRow).ClearContents
end with
 
Upvote 0
Try this
Code:
Private Sub ClearMstrBtn_Click()
'-----------clear master sheet-----------
Dim LastNameRow
With Sheet("Mast")
    LastNameRow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("A2:AB" & LastNameRow).ClearContents
    .Range("A2").Select
End With
End Sub
 
Upvote 0
Re: Sheet functions using a macro on a user form...SOLVED

Code:
Private Sub ClearMstrBtn_Click()
'-----------clear master sheet-----------
Dim LastNameRow As Long
With ActiveWorkbook.Worksheets("Mast")
    LastNameRow = .Range("A" & .Rows.Count).End(xlUp).Row
    .Range("A2:AB" & LastNameRow).ClearContents
End With
End Sub
 
Upvote 0
Re: Sheet functions using a macro on a user form...SOLVED

The problem is/was that you used Sheet instead of Sheets here.
Code:
With Sheet ("Mast")
 
Upvote 0

Forum statistics

Threads
1,203,667
Messages
6,056,651
Members
444,880
Latest member
Kinger1968

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