Looping with Offset Problem

rjsnieg

New Member
Joined
Feb 1, 2022
Messages
10
Office Version
  1. 365
Platform
  1. Windows
Hello Everyone,

I have a fairly basic problem that I cannot figure out.

I have a range L6:GK6 that has random "V"'s throughout the range. When the "V" is present I would like to copy that value and move it up one row. When that is complete remove the "V" from the original range. Then I would like to shift down 2 rows and repeat this process for a defined number of times.

I have the first part down but cannot figure out how to loop through the offset of 2 rows down.

VBA Code:
Sub MOVEVACATIONUP()
Dim cell As Range: Set rng = Application.Range("L6:GK6")
 

    For Each cell In rng
        If cell.Value = "V" Then
            cell.Copy
            cell.Offset(-1, 0).PasteSpecial Paste:=xlValues
        End If
Next cell


    For Each cell In rng
        If cell.Value = "V" Then
        cell.ClearContents
        End If
        
Next cell

End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
I have gotten it to loop to the next row but cannot get it to continue the for statements.

VBA Code:
Sub MOVEVACATIONUP1()
Dim cell As Range: Set rng = Application.Range("L4:GK4")
Dim i As Integer

    Do While i < 120
    
    For Each cell In rng
        If cell.Value = "V" Then
            cell.Copy
            cell.Offset(-1, 0).PasteSpecial Paste:=xlValues
        End If
Next cell

    For Each cell In rng
        If cell.Value = "V" Then
        cell.ClearContents
        End If

Next cell
          i = i + 1
   rng.Offset(2, 0).Select
Loop


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,724
Messages
6,126,485
Members
449,316
Latest member
sravya

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