help on paste values vba please

orsm6

Active Member
Joined
Oct 3, 2012
Messages
496
Office Version
  1. 365
Platform
  1. Windows
Hi all - i was given this sheet (which works) however what i'd like to do is just paste the values this code copies so i can keep the destination sheet formatting as is... this code stops at the active.sheet paste line, how can i modify this? TIA

Code:
Private Sub CopyTXT(destSht As Worksheet, sourceWbk As Workbook)

Set destinationWorkbook = ActiveWorkbook

Dim lastRow As Integer
Dim lastColumn As Integer

lastRow = LastRowNumber(sourceWbk.Sheets(1))
lastColumn = lastColNumber(sourceWbk.Sheets(1))

'copy the data
sourceWbk.Activate
sourceWbk.Sheets(1).Range(Cells(1, 1), Cells(lastRow, lastColumn)).Copy

'Open the sheet you're pasting into
destinationWorkbook.Activate
destSht.Activate

'Pick where to paste
lastRow = LastRowNumber(destSht)
Cells(lastRow + 1, 1).Select
ActiveSheet.PasteSpecial xlPasteValues

'clear the clipboard
Application.CutCopyMode = False

'close the current file
sourceWbk.Close


End Sub
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Assuming that LastRowNumber is a separate function maybe....
VBA Code:
lastRow =  LastRowNumber(destSht)
destSht.Cells(lastRow + 1, 1).PasteSpecial xlPasteValues

Although personally I would name the 2 lastRow variables differently for each sheet. I would also change all the Integers for Longs.
 
Upvote 0
Assuming that LastRowNumber is a separate function maybe....
VBA Code:
lastRow =  LastRowNumber(destSht)
destSht.Cells(lastRow + 1, 1).PasteSpecial xlPasteValues

Although personally I would name the 2 lastRow variables differently for each sheet. I would also change all the Integers for Longs.

Hi Mark, this works perfectly thanks.

Our VBA skills are pretty limited and rely on google etc a lot lol... i am sure if someone with far better understanding looked at the entire set of Macros they would probably gasp in horror haha
 
Upvote 0
You're welcome, the code below is how I would adapt the code that you posted....

VBA Code:
Private Sub CopyTXT(destSht As Worksheet, sourceWbk As Workbook)
    Dim lastRow As Long, LastRowDest As Long
    Dim lastColumn As Long

    lastRow = LastRowNumber(sourceWbk.Sheets(1))
    lastColumn = lastColNumber(sourceWbk.Sheets(1))

    'copy the data
    With sourceWbk.Sheets(1)
        .Range(.Cells(1, 1), .Cells(lastRow, lastColumn)).Copy
    End With

    'Pick where to paste
    LastRowDest = LastRowNumber(destSht)
    destSht.Cells(LastRowDest + 1, 1).PasteSpecial xlPasteValues

    'clear the clipboard
    Application.CutCopyMode = False

    'close the current file
    sourceWbk.Close


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,226
Members
449,303
Latest member
grantrob

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