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

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
Asked:
samprg
  • 7
  • 5
  • 2
2 Solutions
 
etech0Commented:
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
 
etech0Commented:
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
 
kgerbChief 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

Open in new window

Kyle
Q-27419157-RevA.xlsm
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
samprgAuthor Commented:
I think this micro, I do not want to add macro please
0
 
kgerbChief EngineerCommented:
so you don't want vba?  You want a formula?
0
 
etech0Commented:
I'm sorry, I didn't understand that. Can you rephrase?
0
 
etech0Commented:
What's the highest possible value in row b?
0
 
samprgAuthor Commented:
Yes, I want a formula
0
 
samprgAuthor Commented:
etech0:
In Column B (3) is how many times for loop
0
 
etech0Commented:
It will always be 3?
0
 
samprgAuthor Commented:
Yes
0
 
etech0Commented:
in c3 type:
=a1&"&"&a1-1&"&"&a1-2

then copy down the column
0
 
etech0Commented:
I meant type it in c1 and copy down, or start in your first row of data.
0
 
samprgAuthor 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.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 7
  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now