How can I shift all cells right based on a cell value?

grooveriw

New Member
Joined
May 1, 2017
Messages
3
I am looking for a way to shift all the cells in a row to the right based on the value in one of the cells in that row as my manually created sample below shows.
In this example, I want to shift the cells right based on the value in column A.
Original Spreadsheet:-
ABCD
10111111John54
21111211Bob34
32111212Fred2
42111214Chris0
51111215Jane1
61111220Joan17
72121101Sally25
83121110Harry4
92121113Henry9

<tbody>
</tbody>

After:-
ABCDEFG
10111111John54
21111211Bob34
32111212Fred2
42111214Chris0
51111215Jane1
61111220Joan17
72121101Sally25
83121110Harry4
92121113Henry9

<tbody>
</tbody>

Thank you in advance.
I just know that some genius out there will know how to do it.
many regards
Graham
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Code:
Dim rng As Range, cel As Range
Set rng = Range([A1], Cells(Rows.Count, 1).End(xlUp))
For Each cel In rng
    If cel > 0 Then cel.Resize(, cel).Insert Shift:=xlToRight
Next
 
Upvote 0
Thanks footoo,
I have tried entering the code you posted but get an error

Compile error:
Invalid outside procedure

Haven't a clue what this means.

What am I doing wrong?

thanks
 
Upvote 0
You need it to look like this:
Code:
Sub My_Sub()
Dim rng As Range, cel As Range
Set rng = Range([A1], Cells(Rows.Count, 1).End(xlUp))
For Each cel In rng
    If cel > 0 Then cel.Resize(, cel).Insert Shift:=xlToRight
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,926
Messages
6,122,306
Members
449,079
Latest member
juggernaut24

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