98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Loops
Loops
Resolved · Low Priority · Version 2010
Thea has attended:
Excel VBA Intro Intermediate course
Loops
I am trying to develop a code that inserts a column, writes a header and then conducts a formula concatenating 3 other columns. I want to loop the code based on whether the cell in the first column is populated or not.
A B Z AA AB
ID Name Address 1 Address 2 Address 3
00001 James 1 High St London N3 8PL
So when column A becomes blank I want the formula to stop in the new column created in cell AC that concatenates Z, AA and AB.
Hope that makes sense!
Thanks in advance
RE: Loops
Hi Thea,
I have written some code (see below) based on your question . If you copy and paste this code into the code window of your spreadsheet's VBE, you could test it out on some sample data. It worked on my sample spreadsheet. I tried to emulate your spreadsheet's layout.
Sub JoinAddresses()
Columns("AC:AC").Select
Selection.Insert Shift:=xlToRight, _
CopyOrigin:=xlFormatFromLeftOrAbove
'This line adds a column and moves any existing content to the next column.
Range("AC1").Select
ActiveCell = "Address" 'You can replace "Address" with any text
Range("AC2").Select
Do Until ActiveCell.Offset(0, -28) = "" 'Looks at the data in column A
ActiveCell = "=(RC[-3]&"" ""&RC[-2]&"" ""&RC[-1])" 'Concatenates 3 columns
ActiveCell.Offset(1, 0).Select
Loop
Columns("AC:AC").AutoFit
End Sub
Kind regards
Marius Barnard
Excel Trainer
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Selecting constant values onlyIf periodically you need to change all your values back to zero, but leave formulas, text and blank cells as they are select the entire worksheet, choose F5 function key, Special and then Constants and choose the appropriate sub-selections. To enter zero in all the selected cells type 0 and then press Ctrl+Enter. |