userform text box fill selected by a variable

Steve001

Board Regular
Joined
Apr 13, 2017
Messages
62
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Afternoon all

stuck again if some can help me out,

I have a userform with several text boxes on it ie a 7 x 3 grid

I want to be able to populate the contents depending upon a variable

for example if I have

var = 3
string1 = "part1"
string2 = "part2"

so this would populate row 3 on my grid with 3 part1 part2

if I had

var = 1
string1 = "part1"
string2 = "part2"

this would populate row 1 on my grid with 1 part1 part 2

I would like to have 1 piece of code that looks at the variable then decides rather than lots of if statements - so I can use the same code for all the boxes

hope this makes sense

PS please can you put comments on so I can under stand please

Steve
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
I would start off by naming the text boxes in a way that reflected their position on the grid. For this example,

TextBox1_1 TextBox1_2 TextBox1_3
TextBox2_1 TextBox2_2 TextBox2_3
...

Then code like this would do what you want.

Code:
Dim var as Long, String1 as String, String2 as String

Me.Controls("TextBox" & var & "_1").Text = var
Me.Controls("TextBox" & var & "_2").Text = String1
Me.Controls("TextBox" & var & "_3").Text = String2
 
Upvote 0
Hi Mike sorry for the late reply

Working thank you

Steve
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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