Copy rows and paste text not formulas.

sdsdub

New Member
Joined
Jan 3, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
I have code that works exactly how I want it to EXCEPT it pastes formulas (vlookups, lookups, concatenates, adding vales from one column to another, etc...) instead of the text/values in the cells.
I am copying rows from a worksheet into a different worksheet and pasting it in the first empty row.

Sub GetData()
Dim sh4 As Worksheet, sh5 As Worksheet, lr As Long, rng As Range
Set sh4 = Sheets("CopySheet")
Set sh5 = Sheets("PasteSheet")
lr = sh4.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh4.Range("A2:A" & lr)
rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2)
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,163
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How many columns are you copying?
 

sdsdub

New Member
Joined
Jan 3, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hello! Thanks for the welcome. I've been using Mr. Excel for a long time and this is the first time I wasn't able to find the answer to a question.

There are 25 columns and 46 rows if that matters as well. I don't think I'll ever have more than 46 rows to copy.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,163
Office Version
  1. 365
Platform
  1. Windows
Ok, how about
VBA Code:
Sub GetData()

   Dim sh4 As Worksheet, sh5 As Worksheet, lr As Long, rng As Range
   Set sh4 = Sheets("CopySheet")
   Set sh5 = Sheets("PasteSheet")
   lr = sh4.Cells(Rows.Count, 1).End(xlUp).Row
   Set rng = sh4.Range("A2:A" & lr).Resize(, 25)
   sh5.Cells(Rows.Count, 1).End(xlUp)(2).Resize(rng.Rows.Count, 25).Value = rng.Value
End Sub
 
Solution

rollis13

Well-known Member
Joined
Jul 30, 2012
Messages
780
Office Version
  1. 2016
Platform
  1. Windows

ADVERTISEMENT

Change your Copy/Paste code from:
Code:
rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2)
to this:
VBA Code:
rng.EntireRow.Copy
sh5.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
Oh, sorry, didn't update my page. Hi to all :).
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,163
Office Version
  1. 365
Platform
  1. Windows
It's always best to use the Value=Value approach, otherwise you can end-up with "blank" cells that contain null-strings.
 

sdsdub

New Member
Joined
Jan 3, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

It's always best to use the Value=Value approach, otherwise you can end-up with "blank" cells that contain null-strings.
Thanks! This did exactly what you said it would. It wasn't essential for what I'm doing but it is a nice bonus.
 

sdsdub

New Member
Joined
Jan 3, 2022
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Change your Copy/Paste code from:
Code:
rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2)
to this:
VBA Code:
rng.EntireRow.Copy
sh5.Cells(Rows.Count, 1).End(xlUp)(2).PasteSpecial Paste:=xlPasteValues
Oh, sorry, didn't update my page. Hi to all :).
Thanks! this worked as well as the code in a previous reply. I appreciate your help!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
73,163
Office Version
  1. 365
Platform
  1. Windows
Glad we could help & thanks for the feedback.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,846
Messages
5,833,937
Members
430,247
Latest member
w9u5280o

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