Debugger pointing to code in the red when trying to copy from one workbook to another.
Please Login or Register to view this content.
Debugger pointing to code in the red when trying to copy from one workbook to another.
Please Login or Register to view this content.
try this
Please Login or Register to view this content.
<<< If you have valued anyone's contributions in this thread, please click * to thank them for their efforts
Your code is in a worksheet code module, so any use of Range or Cells that is not qualified with a worksheet will refer to the sheet containing the code, not the active sheet. That means that in this line:
the Range property refers to the active sheet, and the Cells properties refer to a different sheet (the one with the Activate event code), which doesn't make sense.Please Login or Register to view this content.
Rory
Not quite. Let’s say the code is in sheet1. Your original version:
is actually equivalent to:Please Login or Register to view this content.
As far as VBA is concerned, that means you want a reference to a range on Rawdata.ActiveSheet that starts at A5 on sheet1 and goes to another cell on sheet1, which doesn’t make sense. Note: you are not referring to the addresses of the cells (eg “B1”), you are using references to specific actual cells which exist on a specific sheet in a specific workbook.Please Login or Register to view this content.
So it seems I need to qualify cell reference since we are dealing with worksheet event. I understand it wouldn't be able to decipher otherwise which sheet cell reference is referring to.
For workbook I should be able to skip it without necessitating workbook reference.
In a procedure in any worksheet code module (doesn't have to be an event procedure) any unqualified reference to Range or Cells will refer to a range on that sheet, whether it is active or not - it is equivalent to Me.Range or Me.Cells.
In any other module (unless it happens to be a class that implements a Range property), it is the equivalent of Application.Range or Application.Cells, which will generally refer to the active sheet.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks