VBA userform number generator defaulting to wrong spreadsheet need help setting focus please?

TitusandNero

New Member
Joined
Mar 17, 2016
Messages
26
Hi again, (operating on Excel 2007)
You guys have been terrific but I come to you yet again with another glitch in my database. I started as a newbie and from learning on here and watching youtube vids. I've managed to create a multipage userform that populates an excel sheet re-named 'Data'. For the end product I'd eventually like to hide this Data sheet from the end user (prevent tampering) and there to be a front sheet so when you open Excel there's a picture, and an open/show 'userform' button etc. I can create the front sheet but here is the problem. Once I've created the front sheet the number generator on my userform defaults to it and is no longer linked to the Data sheet. So it consistently generates #1 and not the actual next sequential number on the Data sheet. I'm guessing I need the generator to focus? The number generator is a command button (cmdGNCN) which populates a textbox (tbGNCN1). The column in the Data sheet where the number is saved/sourced is column A. Can anybody help? Here is my coding for the number generator.

Private Sub cmdGNCN_click()
Me.tbGNCN1 = Application.WorksheetFunction.Max(Range("A:A")) +1
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try like this

Rich (BB code):
Me.tbGNCN1 = Application.WorksheetFunction.Max(Sheets("Data").Range("A:A")) +1
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,431
Members
452,326
Latest member
johnshaji

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