Remove blanks from list via VBA

  • Thread starter Thread starter TheRobsterUK
  • Start date Start date
T

TheRobsterUK

I have a dynamic list that can have data added/removed from it by the
user. I have got the "adding" part sorted out okay but am having some
trouble with the "removing" part. Here is an example of what my list
looks like:


Code:
--------------------
Name
-----
Tracy
Bob
Anna
Roger
--------------------


So the list is not in alphetical order. What I want to do is be able to
remove any item from the list e.g. remove "Anna":


Code:
--------------------
Name
-----
Tracy
Bob

Roger
--------------------


And then to move all entries below where "Anna" was in order to remove
the blank space e.g.


Code:
--------------------
Name
-----
Tracy
Bob
Roger
--------------------


However I do -not- want to sort the list alphabetically. I want the
names to stay in the exact same order.

Does anyone have any suggestions as to how I can achieve this via a VBA
macro?

Cheers
-Rob

Ps - I should also add that I don't want to do this by deleting the
rows that have the blank cells. Ideally I'd just like to move all the
data beneath the blank cell up by one.
 
Here is some code

Public Sub MoveData()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = iLastRow - 1 To 1 Step -1
If Cells(i, "A").Value = "" Then
Cells(i + 1, "A").Resize(iLastRow - i).Cut
Cells(i, "A").Select
ActiveSheet.Paste
End If
Next i
End Sub



--

HTH

RP
(remove nothere from the email address if mailing direct)


"TheRobsterUK" <[email protected]>
wrote in message
news:[email protected]...
 
How about...


Sub DelBlanks()

On error resume next
set rng =Range("a1:a" & [a65536].End(xlUp).Row)
rng.SpecialCells(xlCellTypeBlanks).Delete

End sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top