Delete blank cells in single column and shift data in that column up

vladlock

New Member
Joined
Dec 25, 2013
Messages
5
Hey guys, if anyone can help me out with this I would really appreciate it. I have multiple columns of data, say B-G. Each column has a different number of rows worth of data in them. What I need to do is be able to delete a selection from a row (which I have figured out how to do) then I need to shift the data in that column up one so that there are no blanks between the data. The only command I have been able to find ends up deleting the entire row and thereby compromising the data in the other columns. Here is a copy of what I have so far for a single column.

Dim c As Range
Dim rng As Range
Dim i As Integer
If S4OB = True Then 'selects the list of names on a shift
For Each c In Range("b1:b100") 'finds the name in the shift and deletes it
If c = ComboBox1.Text Then Range("b" & c.row & ":b" & c.row).ClearContents
Next c
For i = 1 To 100 'finds the blank cell and shifts the data in just that column up
If ("b" & i) = "" Then
Range("b" & i).Select
Selection.Delete.shift.xlUp
End If
Next i
End If
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

farmerscott

Well-known Member
Joined
Jan 26, 2013
Messages
813
Office Version
  1. 365
Platform
  1. Windows
Vladlock,

No VBA expert, when you are deleting it is best to start at the bottom and work your way up the column.

Code:
Dim c As Range
Dim rng As Range
Dim i As Integer

If S4OB = True Then                               'selects the list of names on a shift
For Each c In Range("b1:b100")                 'finds the name in the shift and deletes it
If c = ComboBox1.Text Then Range("B" & c).ClearContents
Next c
For i = 100 To 1 'finds the blank cell and shifts the data in just that column up
If ("b" & i) = "" Then
Range("b" & i).Delete.shift.xlUp
End If
Next i
End If

Hope that helps,

FarmerScott
 

Watch MrExcel Video

Forum statistics

Threads
1,122,232
Messages
5,594,956
Members
413,954
Latest member
mrsandy

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
Top