Home > Software design >  Excel VBA - Add word after pasting
Excel VBA - Add word after pasting

Time:11-24

I'm trying to add the word "Model" after pasting data, and I thought I could just put & " Model" after the paste, so it'd be "Paste what you find and (add) Model", but I get debug error:

enter image description here

Am I not using the right paste type?

Here's the code, if needed:

If Model.Rows.Count > 1 Then
    Model.Columns(1).SpecialCells(xlCellTypeConstants).Copy
    .Cells(n   1, "E").PasteSpecial xlPasteValues & " Model"
    Model.Columns(2).SpecialCells(xlCellTypeConstants).Copy
    .Cells(n   1, "Q").PasteSpecial xlPasteValues
  Else
    Model.Columns(1).Copy
    .Cells(n   1, "E").PasteSpecial xlPasteValues & " Model"
    Model.Columns(2).Copy
    .Cells(n   1, "Q").PasteSpecial xlPasteValues
  End If

The 2nd copy/paste is just for numbers, nothing needs added there.

Any help would be greatly appreciated!

CodePudding user response:

Instead of

.Cells(n   1, "E").PasteSpecial xlPasteValues & " Model"

you'll need to do something like

.Cells(n   1, "E").PasteSpecial xlPasteValues
.Cells(n   1, "E").Value = .Cells(n   1, "E").Value & " Model"
  • Related