Shift cells left if adjacent columns are blank using VBA

Trebor8484

Board Regular
Joined
Oct 27, 2018
Messages
69
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

Can anyone assist with a vba solution to the below problem please.

So I have from column I to column R columns labelled as follows:

Job Desc 1
Quantity 1
Job Desc 2
Quantity 2
Job Desc 3
Quantity 3
Job Desc 4
Quantity 4
Job Desc 5
Quantity 5

What I need to do is, working from right to left identify if there are any charges listed in Job Desc 5/Quantity 5. If there are but Job Desc 4/Quantity 4 are empty then it needs to move the values from Job Desc 5/Quantity 5 into Job Desc 4/Quantity 4. Basically, there can be no empty columns. If there are charges then they need to be populated in Job Desc 1/Quantity 1 first before moving across.


2qso2g6.png
[/IMG]

Thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
See if this does what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub ShiftLeftColumnItoR()
  Dim LastRow As Long
  LastRow = Columns("I:R").Find("*", , xlValues, , xlRows, xlPrevious, , , False).Row
  Range("I2:R" & LastRow).SpecialCells(xlBlanks).Delete xlShiftToLeft
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Thanks Rick, that works great

I was thinking I would end up having to write a for loop with range offsets and lots of copy and pasting. Didn't realise a one liner would do it....!
 
Upvote 0
Rick, I have found an issue with this where if there are values in adjacent columns, for example column S then it shifts them as well. I need it to ignore anything that isn't in the specified range I:R
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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