Formerly Best Training
© 2024 STL. All Rights Reserved.
All prices offered for business users and exclude VAT. E&OE
2nd Floor, CA House, 1 Northey Street, Limehouse Basin, London, E14 8BT. United Kingdom
Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Copy cells by using do while
Resolved · Urgent Priority · Version 2007
Carmen has attended:
Excel VBA Intro Intermediate course
I am trying to copy the value in cell C9 into the next 4 rows vertically. After that copy again the value in cell C14 and paste it into the next 4 rows, after the value in C19 and paste it into th next 4, by repeating always the same sequence. I would like to repeat that process all along the column and being able to stop it when there is no more values after counting 4 rows.
I have done this so far, but the macro never stops. Any suggestions to make it work?
Range("C9").select
a = activecell.value
do until a = ""
do until activecell.value <> a
If activecell.offset (1,0) = "" Then
selection.copy
activecell.offset(1,0).select
activesheet.paste
else
activecell.offset (1,0).select
End if
Loop
a =activecell.value
Loop
End sub
Hi Carmen
Thanks for getting in touch. There's a bit of a clash in the code as the loop stops when there is an empty cell immediately below the ActiveCell, however it's only going to copy when there is an empty cell below the ActiveCell.
Does the following help?
Sub Paste4Cells()
Range("C9").Select
Do Until ActiveCell.Offset(4, 0) = ""
a = ActiveCell.Value
For i = 1 To 3
ActiveCell.Offset(i, 0) = a
Next i
ActiveCell.Offset(4, 0).Select
Loop
End Sub
* The loop runs until the 4th cell down is empty
* When it picks up a value, it copies it to the three cells underneath
Kind regards
Gary Fenn
Microsoft Office Specialist Trainer
Tel: 0207 987 3777
Best STL - https://www.stl-training.co.uk
98%+ recommend us
London's leader with UK wide delivery in Microsoft Office training and management training to global brands, FTSE 100, SME's and the public sector
|
Excel tip:Calculate age or serviceThe DATEDIF() function in Excel calculates the number of days, months, or years between two dates. So, this function makes it easy to calculate a person's age. To try this tip: |
We'll call during UK business hours
Server loaded in 0.08 secs.