?
Solved

Loop

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

Expert Comment

by:etech0
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

by:etech0
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

by:
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

Open in new window

Kyle
Q-27419157-RevA.xlsm
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

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

Expert Comment

by:kgerb
ID: 37040501
so you don't want vba?  You want a formula?
0
 
LVL 10

Expert Comment

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

Expert Comment

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

Author Comment

by:samprg
ID: 37040523
Yes, I want a formula
0
 

Author Comment

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

Expert Comment

by:etech0
ID: 37040569
It will always be 3?
0
 

Author Comment

by:samprg
ID: 37040590
Yes
0
 
LVL 10

Expert Comment

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

then copy down the column
0
 
LVL 10

Assisted Solution

by:etech0
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

by:samprg
ID: 37042814
Thanks
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…

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.

Join & Ask a Question