Inserting a cell when it contain specific words and moving original cell to the right

paulc9499

New Member
Joined
May 24, 2017
Messages
10
Hi,

I need to insert a cell and move the original cell to the right but only if the cell contains a specific word.

I have managed to get it to find the cell in the range and highlight the text in bold (which i don't need to do) but are struggling to get it to insert a cell in its place and moving everything to the right.

Any help gratefully received

Many thanks
Paul
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
Public Sub MoveAdminToRight()

Dim lastRow As Long
Dim thisRow As Long
Const SearchColumn = "A" ' Change this to be the column that needs to be moved
Const SearchText = "admin" ' Change this to be the text we're looking for
Const ColumnCount = 8 ' Change this to be the number of columns to insert

lastRow = Cells(Rows.Count, SearchColumn).End(xlUp).Row

For thisRow = 1 To lastRow
    If Cells(thisRow, SearchColumn).Value = SearchText Then
        Cells(thisRow, SearchColumn).Resize(1, ColumnCount).Insert xlShiftToRight
    End If
Next thisRow

End Sub

WBD
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,352
Members
453,033
Latest member
lapmangviettel

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