Solved

Loop

Posted on 2011-10-27
Medium Priority
367 Views
Hello,
I need "loop" in Excel 2010 , please see in below. Thanks
Cell   A    -   B  - Result in C
2011    3        2011&2010&2009
0
Question by:samprg
• 7
• 5
• 2

LVL 10

Expert Comment

ID: 37040453
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

LVL 10

Expert Comment

ID: 37040462
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

LVL 12

Accepted Solution

kgerb earned 1000 total points
ID: 37040483
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 Comment

ID: 37040485
I think this micro, I do not want to add macro please
0

LVL 12

Expert Comment

ID: 37040501
so you don't want vba?  You want a formula?
0

LVL 10

Expert Comment

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

LVL 10

Expert Comment

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

Author Comment

ID: 37040523
Yes, I want a formula
0

Author Comment

ID: 37040531
etech0:
In Column B (3) is how many times for loop
0

LVL 10

Expert Comment

ID: 37040569
It will always be 3?
0

Author Comment

ID: 37040590
Yes
0

LVL 10

Expert Comment

ID: 37040597
in c3 type:
=a1&"&"&a1-1&"&"&a1-2

then copy down the column
0

LVL 10

Assisted Solution

etech0 earned 1000 total points
ID: 37040600
I meant type it in c1 and copy down, or start in your first row of data.
0

Author Closing Comment

ID: 37042814
Thanks
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This holiday season, weâ€™re giving away the gift of knowledgeâ€”tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to usâ€¦
Suggested Courses
Course of the Month15 days, 1 hour left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.