Populating Text Boxes When Userform is Opened

nasa09

New Member
Joined
Oct 3, 2013
Messages
43
I've got a workbook with two worksheets titled "Input" and "Data," and a for titled frmFeeWaiver. When the form is opened, I'd like to populate the text boxes within that form using data from the current row on the the two worksheets.

I tried the following code, but nothing happens when the form is opened. Would somebody mind taking a look and telling me what I've done wrong?

(FYI, the two worksheets have corresponding data, but the row number on the "Data" sheet is different than the row number on "Input," hence the separate row number variables.)

Code:
Private Sub frmFeeWaiver_Activate()

Dim inputRow As Integer
Dim dataRow As Integer

inputRow = ActiveCell.Row
dataRow = inputRow - 5

txtReconPaid.Value = Sheets("Input").Range("L" & inputRow).Value
txtReconWaived.Value = Sheets("Data").Range("AB" & dataRow).Value
txtReconIn.Value = Sheets("Data").Range("AC" & dataRow).Value
txtStmtPaid.Value = Sheets("Input").Range("M" & inputRow).Value
txtStmtWaived.Value = Sheets("Data").Range("AE" & dataRow).Value
txtStmtIn.Value = Sheets("Data").Range("AF" & dataRow).Value
txtFaxPaid.Value = Sheets("Input").Range("N" & inputRow).Value
txtFaxWaived.Value = Sheets("Data").Range("AH" & dataRow).Value
txtFaxIn.Value = Sheets("Data").Range("AI" & dataRow).Value
txtUpdatePaid.Value = Sheets("Input").Range("O" & inputRow).Value
txtUpdateWaived.Value = Sheets("Data").Range("AK" & dataRow).Value
txtUpdateIn.Value = Sheets("Data").Range("AL" & dataRow).Value
txtAssnPaid.Value = Sheets("Input").Range("P" & inputRow).Value
txtAssnWaived.Value = Sheets("Data").Range("AN" & dataRow).Value
txtAssnIn.Value = Sheets("Data").Range("AO" & dataRow).Value
 

End Sub

Any help that you can provide would be greatly appreciated!!!
 

Some videos you may like

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

nasa09

New Member
Joined
Oct 3, 2013
Messages
43
Apparently it should! That fixed the problem. Thank you very much.

I thought that the Sub name should reference the actual form name, but apparently not.

Since the Sub doesn't refer specifically to the form in question, what prevents the same Sub from running when a different, unrelated form is opened?
 

V_Malkoti

Well-known Member
Joined
Jun 10, 2015
Messages
898
Each UserForm gets its own code module. And since the scope of sub is Private, it cannot be accessed from any other module.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,968
Members
414,115
Latest member
SFUser

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
Top