Paste special in VBA

Scottie7275

New Member
Joined
Jul 27, 2017
Messages
13
Hi,

I have the following code which creates a table in a worksheet based on data copied from another worksheet. However it throws up a syntax error and everything I have tried isn't working.

Code:
 With Sheets("Data")        x = .Cells(1, .Columns.Count).End(xlToLeft).Column
        On Error Resume Next
        Set rng = .Cells(1, 1).Resize(, x).Find(what:=Sheets("New Product or Supplier").Cells(4, 3).Value, LookIn:=xlValues, lookat:=xlWhole)
        On Error GoTo 0
        
        If Not rng Is Nothing Then
            .Cells(.Rows.Count, rng.Column).End(xlUp).Offset(1).Value = Sheets("New Product or Supplier").Cells(4, 4).Value
            Set rng = Nothing
        Else
             Dim NextCol As Long
    If Sheets("Data").Range("A1").Value = "" Then
        NextCol = 1
    Else
        NextCol = Sheets("Data").Cells(1, Columns.Count).End(xlToLeft).Column + 1
    End If
    Sheets("New Product or Supplier").Range("C4").Copy Sheets("Data").Cells(1, NextCol).PasteSpecial xlPasteValuesAndNumberFormats
    Sheets("New Product or Supplier").Range("D4").Copy Sheets("Data").Cells(2, NextCol).PasteSpecial xlPasteValuesAndNumberFormats

I want to paste the values but not the formats etc.

Thanks for any help.

Scott
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
try
Code:
   Sheets("New Product or Supplier").Range("C4").Copy
   Sheets("Data").Cells(1, NextCol).PasteSpecial xlPasteValuesAndNumberFormats
   Sheets("New Product or Supplier").Range("D4").Copy
   Sheets("Data").Cells(2, NextCol).PasteSpecial xlPasteValuesAndNumberFormats
Alternaively if you just want values
Code:
    Sheets("Data").Cells(1, NextCol).Value = Sheets("New Product or Supplier").Range("C4").Value
    Sheets("Data").Cells(2, NextCol).Value = Sheets("New Product or Supplier").Range("D4").Value
 
Last edited:
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,218
Members
453,024
Latest member
Wingit77

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