vba Useform Initialize/Open

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Hi,

I have a routine that runs when a command button is pressed on a userform, this works fine, basically it will add the info from row 2 into the userform. The info in Row 2 comes from a series of Vlookups based upon the value in A1.

So basically if they click the command button "next" the routine does the following

Code:
Range("A1").Select
ActiveCell.Value=ActiveCell.Value +1
With Sheets("LookupTables")
   TextBox1.Text = .Range("LookupTables!A2").Value
   TextBox2.Text = .Range("LookupTables!B2").Value etc etc
   End With
Thereby changing the values of the text boxes in the UserForm

However when i open this userform, triggered by a userform1.show command the boxes are empty and only fill after the user selects next of previous. I've played with copying the same "with" command into a PrivateSub Userform_initialize() but this doesn't seem to work. I'm wondering whether i'm putting that code in the wrong place? i've been putting it in a module? or is there another comman i should be using to trigger this?

Any help would be appreciated

Thanks

Ben

Sorry had a brainstorm and figured it out, you have to paste the Private Sub within the Userform Code, not a module.
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,215,798
Messages
6,126,974
Members
449,351
Latest member
Sylvine

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