Solved

Eliminating blank spaces

Posted on 2013-01-21
7
169 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 45

Accepted Solution

by:
Martin Liss earned 120 total points
Comment Utility
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

Expert Comment

by:teylyn
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:pwflexner
Comment Utility
Actually the blank spaces in column A have a "" in them, if this matters...
0
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
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
Comment Utility
Thanks to all, but this answer worked best for my needs.
0
 
LVL 45

Expert Comment

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

Marty - MVP 2009 to 2012
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now