Invalid reference Error

maheshrk81

Board Regular
Joined
Jan 5, 2010
Messages
153
Hi Team,

While running the below Macro, I am getting the below error. This was working fine and suddenly stopped. Can someone help please.

1643353447076.png


Sub CopyPaste()

Application.ScreenUpdating = False
Sheets("EDL Input").Select <--- Getting Error Here
Range("A2:D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A2").Select
Sheets("Load Data").Select <--- Getting Error Here
Range("B2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("EDL Input").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F2").Select
ActiveWorkbook.Save
End Sub

Thanks,
M
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi All,

I updated the code with Declaring the worksheets and it worked well.

Sub CopyPaste()

Dim wb As Workbook
Dim ws As Worksheet
Dim wss As Worksheet

Application.ScreenUpdating = False
Set wb = ActiveWorkbook
Set wss = Sheets("EDL Input")
wb.Activate
wss.Select
Range("A2:D2").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A2").Select
Set wb = ActiveWorkbook
Set ws = Sheets("Load Data")
ws.Select
Range("B2:E2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Set wb = ActiveWorkbook
Set wss = Sheets("EDL Input")
wb.Activate
wss.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F2").Select
ActiveWorkbook.Save
End Sub

Thanls,
M
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,834
Members
449,192
Latest member
mcgeeaudrey

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