PasteSpecial & xlPasteValuesAndNumbersFormats

Millsio88

New Member
Joined
May 1, 2020
Messages
8
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

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,540
Office Version
  1. 365
Platform
  1. Windows
You need to remove the s after Number, you also don't need the resize on that line.
 

Millsio88

New Member
Joined
May 1, 2020
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Legend!, been stumped on that for a while - thanks a lot
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
74,540
Office Version
  1. 365
Platform
  1. Windows
You're welcome & 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,167,532
Messages
5,854,288
Members
431,636
Latest member
shabbas313

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