0

trying to copy data from user workbook to master workbook, code was running good but all of sudden it started throwing the error " paste special method of range class failed " when I check, I found that when I am asking VBA to open my master file "marching ants" around the copied range from user file disappear. please suggest how can i solve this issue

Sub trail13()




Dim WB As ThisWorkbook
Dim s As Worksheet
Dim wbo As Workbook
Dim so As Worksheet
Dim cell As Range

Dim r As Range

Dim W As Range, lastclm As Long, lastrow As Long
Dim source As Range
Dim msource As Range
Dim k As Long
Dim m As Integer
Dim d As Long


Dim z As Long
Dim q As Long
Dim w2 As Range
Dim x As Range
Dim y As Long

Dim mlkup As Range


Cells.Find("Wuerth Art No").Select

Set s = ActiveSheet
Set W = ActiveCell



lastrow = s.Cells(s.Rows.Count, W.Column).End(xlUp).Row
lastclm = s.Cells(W.Row, s.Columns.Count).End(xlToLeft).Column
Set source = s.Range(W, Cells(lastrow, lastclm)) 'source for vlookup
Set msource = s.Range(W, Cells(W.Row, lastclm)) 'source for match function

W.Offset(1, 0).Select

Range(Selection, Selection.End(xlDown)).Select
Selection.Copy





Application.DisplayAlerts = False

On Error Resume Next

Excel.Workbooks.Open ("F:\VBA\New folder\attachments\offer Master of all Customer.xlsx")
Windows("offer master of all customer").Activate

On Error GoTo 0

Set wbo = Workbooks("offer master of all customer")

Set so = wbo.ActiveSheet

so.Cells.Find("WAN").Activate

 

Range("D" & Rows.Count).End(xlUp).Select

Application.CutCopyMode = True

ActiveCell.Offset(1, 0).Range("A1").PasteSpecial xlPasteFormats

   

'ActiveCell.Offset(1, 0).PasteSpecial 'wan paste from user file
BigBen
  • 46,229
  • 7
  • 24
  • 40
  • 1
    [This answer](https://stackoverflow.com/a/45196115/4996248) to the linked question seems to point to both the source of the error (opening or creating a new workbook after the initial copy but prior to pasting) and the solution (don't use `Select`!). More generally, you might benefit from reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/q/10714251/4996248). – John Coleman Feb 15 '21 at 17:45
  • 1
    Generally the copy and paste steps should be as close to each other as possible, otherwise intermediate steps may inadvertently clear the clipboard. – BigBen Feb 15 '21 at 17:48

0 Answers0