Eliminating blank spaces

I'm sure this question has a very simple answer that I should know, but don't.  In the cells of column A are either a number or blank.  The numbers appear every so often, with the blank cells in between.  In column B I want to just show the numbers.  Example:

Column A        Column B
4
2
4                     3
5
2

3

5

How do I generate column B?
Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
In a macro.

``````Dim lngLastRow as Long
Dim lngIndex As Long
Dim lngRow As Long
lngLastRow = Range("A65536").End(xlUp).Row

lngRow = 2
For lngIndex = 2 To lngLastRow
If Cells(lngIndex, 1).Value <> "" Then
Cells(lngRow, 2).Value = Cells(lngIndex, 1).Value
lngRow = lngRow + 1
End If
Next
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Microsoft MVP ExcelCommented:
Hello,

there are several ways.

Copy and paste the data, then sort the pasted values. Or use a formula

If you don't want to sort, you can use a helper column and a formula. Insert a column after column A and starting in row 2 (assuming row 1 has labels)

=IF(A2<>"",ROW(),"")

copy down

Then use in C2

=INDEX(A:A,SMALL(B:B,ROW(A1)))

copy down. Copy the result up to the error message and paste as values.

cheers, teylyn
0
Commented:
you could:

Add a filter to the top row.
Filter on Blanks in column A.
Highlight all rows

This will delete all rows without values in the filtered column.
0
Author Commented:
Actually the blank spaces in column A have a "" in them, if this matters...
0
Older than dirtCommented:
Well then in my code just substitute that character (which I can't make out) in this line

If Cells(lngIndex, 1).Value <> ""
0
Author Commented:
Thanks to all, but this answer worked best for my needs.
0
Older than dirtCommented:
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.