Concatanate variable name

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.
 
J

Jake Marx

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

Top