Cutting and Pasting Range Based on Text in Column to the Left (Updated)

FrenchCelt

Board Regular
Joined
May 22, 2018
Messages
214
Office Version
  1. 365
Platform
  1. Windows
I need to code my macro to look for 4STOP or 3STOP in Row 3 and then cut all data in the next column and paste in Row 16 of the column where the 4STOP/3STOP is located.

For example, I have a 4STOP in Column D. I need to then cut E1:E14 and paste in D17 and then move on to the next 4STOP/3STOP and repeat. I need the emptied column deleted and I need to make sure the data from Row 1 in included in the cut/paste.

Any suggestions?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
If this pastes to the wrong row, you can change it on this line:

Rich (BB code):
Intersect(.UsedRange, Columns(fn.Column + 1)).Cut .Cells(17, fn.Column)
Just change the 17 to the row you want. Change in two places.

VBA Code:
Sub t()
Dim fn As Range, adr As String
    With ActiveSheet
        Set fn = .Rows(3).Find("4STOP", , xlValues, xlWhole)
            If Not fn Is Nothing Then
                adr = fn.Address
                Do
                    Intersect(.UsedRange, Columns(fn.Column + 1)).Cut .Cells(17, fn.Column)
                    Set fn = .Rows(3).FindNext(fn)
                Loop While fn.Address <> adr
                Set fn = Nothing
            End If
        Set fn = .Rows(3).Find("3STOP", , xlValues, xlWhole)
            If Not fn Is Nothing Then
                adr = fn.Address
                Do
                    Intersect(.UsedRange, Columns(fn.Column + 1)).Cut .Cells(17, fn.Column)
                    Set fn = .Rows(3).FindNext(fn)
                Loop While fn.Address <> adr
                Set fn = Nothing
            End If
        .Range("A3", .Cells(3, Columns.Count).End(xlToLeft)).SpecialCells(xlCellTypeBlanks).EntireColumn.Delete
    End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,808
Messages
6,127,008
Members
449,351
Latest member
Sylvine

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