Concatanate variable name

  • Thread starter Thread starter choco140
  • Start date Start date
C

choco140

I got four control on an userform named Date1, Date2, Date3 and Date4.
I am trying to fill them in with this small macro, it doesn't work
because my concatenation doesn't seem to be properly set up...

Sub Test
For i = 1 to 4
Date & i &.value = Range("A" & i).Value
Next i
End Sub

I got an error for "Date & i &.value", any idea how to solve this?

Thanks.
 
Hi choco140,

You can't concatenate variable names directly, as VBA will not understand
it. You can, however, work with the Controls collection to do this:

Dim i As Integer

For i = 1 To 4
Me.Controls("Date" & CStr(i)).Text = _
Sheets("Sheet1").Cells(i, 1).Value
Next i
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Step thru Dates 4
MATCH command does not work with dates 3
union range 5
For Next Issue 5
Variables From TextBoxes 1
if statements vs date ranges 1
repeat entry based on value in cell 6
Lists with dates in them 2

Back
Top