Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Eliminating blank spaces

Posted on 2013-01-21
7
Medium Priority
?
217 Views
Last Modified: 2013-01-21
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?
0
Comment
Question by:pwflexner
7 Comments
 
LVL 49

Accepted Solution

by:
Martin Liss earned 480 total points
ID: 38803151
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

Open in new window

0
 
LVL 50
ID: 38803169
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
 
LVL 24

Expert Comment

by:Steve
ID: 38803327
you could:

Add a filter to the top row.
Filter on Blanks in column A.
Highlight all rows
Press [ctrl]+[numpad minus]

This will delete all rows without values in the filtered column.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:pwflexner
ID: 38803454
Actually the blank spaces in column A have a "" in them, if this matters...
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38803476
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 Closing Comment

by:pwflexner
ID: 38803490
Thanks to all, but this answer worked best for my needs.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38803492
You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question