VBA stacking multiple columns and pasting with paste special

RobFL

New Member
Joined
Feb 19, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi,

I have 5 columns I need to stack in one column on a separate sheet (columns AD, AE, AF, AG and AH). Using the forum I was able to find code to copy two columns from the "CQ All Facts Report" sheet and stack it to column A on the "MemberText" sheet. I was just going to follow the same logic for the other three columns. The columns are not going to be the same length each time the sheet is updated with new data. The problem I am encountering is the columns on the CQ All Facts Report are formulas. I have been trying to add paste special to it so it only pastes the values but I cannot seem to figure out where to add that without getting an error. Here is the code that copies over everything including the formulas. I was trying to add pastespecial xlpastevalues after the Cells references but it is not working. Is there a way to modify this to have it paste values rather than the formulas? Thanks in advance!

VBA Code:
Sub Copy_Columns()
'Modified 6/19/2020 1:58:23 PM EST
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets("CQ All Facts Report").Cells(Rows.Count, "AD").End(xlUp).Row
Dim Lastrowa As Long
Lastrowa = Sheets("MemberText").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("CQ All Facts Report").Cells(2, "AD").Resize(Lastrow).Copy Sheets("MemberText").Cells(1, 1)
Lastrowa = Sheets("MemberText").Cells(Rows.Count, "A").End(xlUp).Row + 1
Lastrow = Sheets("CQ All Facts Report").Cells(Rows.Count, "AE").End(xlUp).Row
Sheets("CQ All Facts Report").Cells(2, "AE").Resize(Lastrow).Copy Sheets("MemberText").Cells(Lastrowa, 1)
Application.ScreenUpdating = True
End Sub
 
Last edited by a moderator:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,666
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Copy_Columns()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets("CQ All Facts Report").Cells(Rows.Count, "AD").End(xlUp).Row
Dim Lastrowa As Long
With Sheets("MemberText")
   Lastrowa = .Cells(Rows.Count, "A").End(xlUp).Row + 1
   .Cells(Lastrowa, 1).Resize(Lastrow).Value = Sheets("CQ All Facts Report").Cells(2, "AD").Resize(Lastrow).Value
   Lastrowa = .Cells(Rows.Count, "A").End(xlUp).Row + 1
   Lastrow = Sheets("CQ All Facts Report").Cells(Rows.Count, "AE").End(xlUp).Row
   .Cells(Lastrowa, 1).Resize(Lastrow).Value = Sheets("CQ All Facts Report").Cells(2, "AE").Resize(Lastrow).Value
End With
Application.ScreenUpdating = True
End Sub
 
Solution

RobFL

New Member
Joined
Feb 19, 2021
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Copy_Columns()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Sheets("CQ All Facts Report").Cells(Rows.Count, "AD").End(xlUp).Row
Dim Lastrowa As Long
With Sheets("MemberText")
   Lastrowa = .Cells(Rows.Count, "A").End(xlUp).Row + 1
   .Cells(Lastrowa, 1).Resize(Lastrow).Value = Sheets("CQ All Facts Report").Cells(2, "AD").Resize(Lastrow).Value
   Lastrowa = .Cells(Rows.Count, "A").End(xlUp).Row + 1
   Lastrow = Sheets("CQ All Facts Report").Cells(Rows.Count, "AE").End(xlUp).Row
   .Cells(Lastrowa, 1).Resize(Lastrow).Value = Sheets("CQ All Facts Report").Cells(2, "AE").Resize(Lastrow).Value
End With
Application.ScreenUpdating = True
End Sub
Thanks for your help and quick response! That worked and I really appreciate it. Thanks for teaching me the new set up.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,666
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,766
Messages
5,638,236
Members
417,016
Latest member
Tegguy

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
Top