PasteSpecial & xlPasteValuesAndNumbersFormats

Millsio88

New Member
Joined
May 1, 2020
Messages
11
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I can't seem get my code to work where on the Input tab I want cell D4 to copy and paste just values and numbers into the B column on the KM Tab. There is a formula in D4 which is (=MAX(Detailis!B4:B51)+1) which results in 'D005' and will increase when new items get added to the list.

The issue I'm having is I need these ref numbers 'D00X' to also be copied into the KM tab but pasted as the values and number format as there are also 'KM0X' refs on the KM tab.

I keep getting errors for the code from 'pastespecial method of range class failed' to 'unable to get the pastespecial property of the range class' but can't get the result on the B column on the KM tab to be 'D005'

can anyone help or advise what I'm doing wrong?

Sub CopySource()
Dim wsData As Worksheet
Dim iRow As Long
Set wsData = Sheets("Input")

With Worksheets("Details")
iRow = .Cells(Rows.Count, 2).End(xlUp).Row + 1
.Range("B" & iRow).Resize(, 21).Value = Application.Transpose(wsData.Range("D4:D25").Value)
End With

With Worksheets("KM")
iRow = .Cells(Rows.Count, 2).End(xlUp).Row + 1
wsData.Range("D4").Copy
.Range("B" & iRow).Resize(, 1).PasteSpecial Paste:=xlPasteValuesAndNumbersFormats

.Range("C" & iRow).Resize(, 20).Value = Application.Transpose(wsData.Range("D5:D25").Value)
End With

End Sub
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
You need to remove the s after Number, you also don't need the resize on that line.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,521
Messages
6,114,109
Members
448,548
Latest member
harryls

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