For ...Next loop help please

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Anyone know where I am going wrong with this code:

Dim i as byte

Dim Fund1 As String
Dim Fund2 As String

For i = 1 to 2

"Fund" & i = Sheets("S1").Cells(1, i + 1).Value '(which is a string)

Next i

I reckon it should work fine but am obviusly mising something obvious as it
doesn't like the referance to the string variable concatenated from the
string and number: "Fund" & i but I don't know why it doesn't like it.

Apologies I am sure it must be obvious but if someone could point it out I
would be most grateful.

Thanks, Mark
 
Is this what you're trying to get at?

Dim i as byte
Dim Fund as string

for i=1 to 2
Fund=Fund & Sheets("S1").Cells(1,i+1).Value
next i

There are definately other ways to get what you want, but if you want to do
it through a loop, this code will take the text in cells B1 (Cells(1,2)) and
C1 (Cells(1,3)) and concatenate them.
 
Dim i as Long
Dim fund(1 to 2) as String
for i = 1 to 2
Fund(i) = Sheets("S1").Cells(1, i+1).Text
Next
 

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

Back
Top