PasteSpecial & xlPasteValuesAndNumbersFormats

Millsio88

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

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,686
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
5
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
55,686
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,911
Messages
5,627,594
Members
416,255
Latest member
amethystia

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