• Status: Solved
• Priority: Medium
• Security: Public
• Views: 370

# Loop

Hello,
I need "loop" in Excel 2010 , please see in below. Thanks
Cell   A    -   B  - Result in C
2011    3        2011&2010&2009
0
samprg
• 7
• 5
• 2
2 Solutions

Commented:
sub loopmacro()
dim x as integer
dim result as string
for x = 1 to range("B1").value
result = result & range("A1").value - (x - 1)
next x

End sub
0

Commented:
whoops! left out a line...

sub loopmacro()
dim x as integer
dim result as string
for x = 1 to range("B1").value
result = result & range("A1").value - (x - 1)
range("C1").value = result
next x

End sub

if you want this to happen to the whole column, let me know and I'll adjust the macro.
0

Chief EngineerCommented:
I think this code will do it.  I assumed from the word Loop you wanted VBA.  See attached workbook for example.  If you want formulas we can do that too.
``````Sub GoLoop()
Dim rng As Range, i As Long
For Each rng In Range("A1", Cells(Rows.Count, 1).End(xlUp))
rng.Offset(, 2) = rng
For i = 1 To rng.Offset(, 1) - 1
rng.Offset(, 2) = rng.Offset(, 2) & " " & rng - 1 * i
Next i
Next rng
End Sub
``````
Kyle
Q-27419157-RevA.xlsm
0

Author Commented:
I think this micro, I do not want to add macro please
0

Chief EngineerCommented:
so you don't want vba?  You want a formula?
0

Commented:
I'm sorry, I didn't understand that. Can you rephrase?
0

Commented:
What's the highest possible value in row b?
0

Author Commented:
Yes, I want a formula
0

Author Commented:
etech0:
In Column B (3) is how many times for loop
0

Commented:
It will always be 3?
0

Author Commented:
Yes
0

Commented:
in c3 type:
=a1&"&"&a1-1&"&"&a1-2

then copy down the column
0

Commented:
I meant type it in c1 and copy down, or start in your first row of data.
0

Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.