Help with syntaxis

Ephira

New Member
Joined
Jan 8, 2022
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi!, I´m new here
I have a little macro. The problem is that i´m trying to copy a range of another sheet on the same sheet but i think that i have a error syntaxis cuz the macro don´t runs. These are the bad guys:

VBA Code:
Worksheets("plan").Range("G4:K7").Copy: Worksheets("plan").Range(Cells(j, 7), Cells(j + 3, 11)).PasteSpecial xlPasteFormulas
Worksheets("plan").Range("G4:K7").Copy: Worksheets("plan").Range(Cells(j, 7), Cells(j + 3, 11)).PasteSpecial xlPasteFormats
Worksheets("plan").Range("G4:K7").Copy: Worksheets("plan").Range(Cells(j, 7), Cells(j + 3, 11)).PasteSpecial xlPasteValidation

I hope somebody can help me. (Sorry, my english is kind of clumsy)
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi & welcome to MrExcel.
You need to qualify the cells with the sheet, not just the range.
Try it like
VBA Code:
With Worksheets("plan")
   .Range("G4:K7").Copy: .Range(.Cells(j, 7), .Cells(j + 3, 11)).PasteSpecial xlPasteFormulas
   .Range("G4:K7").Copy: .Range(.Cells(j, 7), .Cells(j + 3, 11)).PasteSpecial xlPasteFormats
   .Range("G4:K7").Copy: .Range(.Cells(j, 7), .Cells(j + 3, 11)).PasteSpecial xlPasteValidation
End With
 
Upvote 0
Solution
Hi & welcome to MrExcel.
You need to qualify the cells with the sheet, not just the range.
Try it like
VBA Code:
With Worksheets("plan")
   .Range("G4:K7").Copy: .Range(.Cells(j, 7), .Cells(j + 3, 11)).PasteSpecial xlPasteFormulas
   .Range("G4:K7").Copy: .Range(.Cells(j, 7), .Cells(j + 3, 11)).PasteSpecial xlPasteFormats
   .Range("G4:K7").Copy: .Range(.Cells(j, 7), .Cells(j + 3, 11)).PasteSpecial xlPasteValidation
End With
Oh, you are right!!!! Thank u! Now the macro works.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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