Noob VBA loop question

Faller

New Member
Joined
Jul 22, 2011
Messages
7
I am trying to get a loop running where if there is text in "A3" then it will cut it into C2. Then do the same thing with A5 to C4, A7 to C6 and so on until there is nothing in A(odd). Then I want to delete all the odd rows starting with three (They will all be empty). I can not for the life of me think what to do next. I tried indirect and I know there is a way to make it add to the cell value.

Loop
Sheets("Sheet 1").Select
Pickvar = 3
movevar = 2
cutvar = 2
Do Until IsEmpty(Selection.Value)
ActiveSheet.Range("A" & Pickvar).Select
Selection.Cut Destination = Range("C" & cutvar)
Pickvar = Pickvar + movevar
cutvar = cutvar + movevar

Thank you
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
try this

Code:
Sub sample()
    Sheets("Sheet2").Select
    
    rownum = 3
    
    Do While Cells(rownum, 1) <> ""
        Cells(rownum, 1).Select
        Selection.Cut
        Cells(rownum - 1, 3).Select
        ActiveSheet.Paste
        Rows(rownum).Delete
        rownum = rownum + 1
    Loop
End Sub
 
Upvote 0
Try

Code:
Sub sample()
Dim LR As Long, i As Long
With Sheets("Sheet2")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    If LR Mod 2 = 0 Then LR = LR - 1
    For i = LR To 3 Step -2
        .Range("A" & i).Copy Destination:=.Range("C" & i - 1)
        .Rows(i).Delete
    Next i
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top