VBA: Sheet code name - compile error?

botanist

New Member
Joined
Sep 24, 2020
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi there! I am currently attending an online beginner's VBA course (completely new, so please pardon me here!), and am trying to reference sheets using their code names.

I have written the following code (Office 365), but am getting the "Compile Error: Variable not defined" error when trying to run it. Would anyone know why this is so?

Sheet5.Range("A4").CurrentRegion.Copy Sheet6.Range("A4")

Thank you so much for your help in advance!
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi there, yes, my worksheet code names are Sheet5 and Sheet6 - the default; have not made any changes. Not sure what the issue is ! :confused:
 
Upvote 0
If you're getting that error on that line, then either the code names are different, or those sheets are in a different workbook to the code.
 
Upvote 0
Glad we could help. :) So... which one was it?
 
Upvote 0
I had the module built under my Personal Workbook, rather than the Excel workbook I was working on. All prior codes worked well as there was no references to specific sheets until now.

Thanks so much again! Just beginning my VBA journey, and am so excited!
 
Upvote 0

Forum statistics

Threads
1,214,786
Messages
6,121,548
Members
449,038
Latest member
Guest1337

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