(VBA) Given 2 columns, reading across one row after the next, copy & paste into one column in another sheet.

Opossum8117

New Member
Joined
Oct 30, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi all, first time here, pretty experienced at excel but I have a work problem that seems to need VBA to solve. Unfortunately my VBA abilities only extend to importing sheets and copy and pasting cells.

Like in the title, I have data in 2 columns, extending for a maximum of 1000 rows. Reading across one row after the other, I would like it to be copied and pasted into a single column in another sheet. Any blanks in the original data can be copied straight through.

I believe a copy is needed and not a formula reference because the data has line breaks and a simple = doesn't seem to capture that.

Here is a picture to illustrate, any help would be very much appreciated!
1698671381267.png
 

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).
Hi & welcome to MrExcel.
If you don't want the blank cells, how about
Excel Formula:
=TOCOL(A2:B1000,1)
 
Upvote 1
Solution
To keep the blanks, how about
Excel Formula:
=TOCOL(FILTER(A2:B1000&"",A2:A1000<>""))
 
Upvote 1
VBA Code:
Sub test()
  Dim column1 As Variant, column2 As Variant
  column1 = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row
  column2 = Range("B2:B" & Cells(Rows.Count, "B").End(xlUp).Row
  
  Range("D" & Cells(Rows.Count, "D").End(xlUp).Row).Offset(1).Resize(Ubound(column1, 1)).Value = column1
  Range("D" & Cells(Rows.Count, "D").End(xlUp).Row).Offset(1).Resize(Ubound(column2, 1)).Value = column2
End Sub
 
Upvote 1
Thank you very much for the code, I'll have a look tomorrow and let you know how it goes! Programming is a whole other art it seems. It appears tocol works as well. Just couldn't find it through my googling.
 
Upvote 0

Forum statistics

Threads
1,215,124
Messages
6,123,184
Members
449,090
Latest member
bes000

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