Copy column data without blanks and paste into adjacent column WITHOUT deleting cells

Richard_mcr

New Member
Joined
Oct 19, 2023
Messages
8
Office Version
  1. 2019
Platform
  1. Windows
Hello!

I have been looking for a solutions and whilst may come close, none are close enough for my limited VBA knowledge to adapt!

Here is my problem: I have data with random blank cells in column A and I would like to copy the data into column B without the blanks; however, I need to maintain the rows to the right and below.

I have tried to use both the skip blanks and delete blanks, however this affects the adjacent cells / rows.

In the image, you can see the random data in A, and how I would like it in B.

Thank you in advance for any assistance!! :)
 

Attachments

  • Problem.png
    Problem.png
    16.6 KB · Views: 11

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
With Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each ([Data] <> null))
in
    #"Filtered Rows"

DataData
11
2
23
4
5
36
7
48
9
510
6
7
8
9
10
 
Upvote 0
VBA Option:
VBA Code:
Option Explicit
Sub SortSomeCells()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ****
    Dim r As Range, c As Range, LRow As Long, i As Long, a
    LRow = ws.Cells(Rows.Count, "A").End(xlUp).Row
    Set r = ws.Range("A2:A" & LRow)
    ReDim a(1 To LRow, 1 To 1)
    i = 1
    
    For Each c In r
        If c <> "" And IsNumeric(c.Value) Then
            a(i, 1) = c
            i = i + 1
        End If
    Next c
    ws.Range("B2").Resize(i).Value = a
End Sub
 
Upvote 0
Welcome to the Board!

Its too bad you do not have Excel 2021 or 365. This is really easy to do with the new FILTER function.
It would just be this one formula:
Excel Formula:
=FILTER(A2:A18,A2:A18<>"")
 
Upvote 0
If your data range in column A is fixed, you could use this:
VBA Code:
Sub SortSomeCells_V2()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ****
    ws.Range("A2:A18").Copy ws.Range("B2")
    ws.Range("B1:B18").Sort Key1:=ws.Cells(1, 2), _
    order1:=xlAscending, Header:=xlYes
End Sub
 
Upvote 1
A 2019 formula option

Book1 (version 1).xlsb
AB
1Data2019
211
32
423
54
65
736
87
948
109
11510
126 
13
147
158
16
179
1810
Sheet6
Cell Formulas
RangeFormula
B2:B12B2=IFERROR(INDEX($A$2:$A$18,SMALL(IF($A$2:$A$18<>"",ROW($A$2:$A$18)-ROW($A$2)+1),ROWS($A$2:$A2))),"")
 
Upvote 1
Hi All,

Thank you for the responses, it's much appreciated!

I've gone down Kevin's VBA option!

Happy days!

:)
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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
Back
Top