Delete Cells in Excel Row based on number in Cell

Allen2014

New Member
Joined
Dec 8, 2014
Messages
5
I have the following data and would like some VBA Code to run down the Rows and based on the number in Column D, Delete the Cells (and Shift Data to the Left) in Columns E to I based on the number in Column D. For example,
In Row 1, to delete Cells F1:I1, as the value is 1; Value retained = "Item1"
In Row 2, to delete Cells in E2 then Cells F2:I2; Value retained = "Item2"
In Row 3, to delete Cells in E3:F3 then Cells F3:I3; Value retained = "Item3"
In Row 4, to delete Cells in F4:I4; and so on ... Value retained = "Item1"
At the end I want only one of the items in Columns E:I in each of the Rows, with the number oin Column D determining which of the Columns Data is retained.
Max number of Columns holding data to be retained is 5, hence looking in Columns E:I, although this may be a variable.
Any assistance is much appreciated.
Thanks
Allen


<tbody>
</tbody>

1ABCDEFGHI
2CompanyAFacilityBGroup1001Item 1Item 2Item 3
3CompanyAFacilityBGroup1002Item 1Item 2Item 3
4CompanyAFacilityBGroup1003Item 1Item 2Item 3
5CompanyBFacilityBGroup2001Item 1Item 2
6CompanyBFacilityBGroup2002Item 1Item 2
7CompanyCFacilityBGroup3001Item 1Item 2Item 3Item 4
8CompanyCFacilityBGroup3002Item 1Item 2Item 3Item 4
9CompanyCFacilityBGroup3003Item 1Item 2Item 3Item 4
10CompanyCFacilityBGroup3004Item 1Item 2Item 3Item 4
11CompanyDFacilityBGroup4001Item 1
12CompanyEFacilityBGroup5001Item 1Item 2Item 3Item 4Item 5
13CompanyEFacilityBGroup5002Item 1Item 2Item 3Item 4Item 5
14CompanyEFacilityBGroup5003Item 1Item 2Item 3Item 4Item 5
15CompanyEFacilityBGroup5004Item 1Item 2Item 3Item 4Item 5
16CompanyEFacilityBGroup5005Item 1Item 2Item 3Item 4Item 5

<colgroup><col><col><col><col><col><col span="5"></colgroup><tbody>
</tbody>

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited:

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,216,119
Messages
6,128,947
Members
449,480
Latest member
yesitisasport

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