Thread: Macro Help
View Single Post
  #3   Report Post  
lostgrave2001 lostgrave2001 is offline
Junior Member
 
Posts: 10
Question

Hello again,

i have tried to edit my code to ecxept "ActiveSheet.Cells(rwIndex, 1).Select" but when i try to change out " Worksheets("Local"

Can someone please help me out please.

Thank you


Quote:
Originally Posted by joeu2004[_2_] View Post
"lostgrave2001" wrote:
Could anyone show me how to change the following macro to activie
sheet/tab rather than having to create a new macro for every tab.

[....]
Do Until Worksheets("local").Cells(rwIndex, 1).Value = ""

[....]
ActiveSheet.Cells(rwIndex, 1).Select

[....]
sline = Worksheets("local").Cells(rwIndex, 1).Value

[....]
Range("W2") = rwIndex - 1


I have not studied your code in detail. But I suspect you entered into a
worksheet object, for example by right-clicking on the worksheet tab and
clicking on View Code.

If that is the case, in VBA, click on Insert, then Module. Then cut
(ctrl+X) the text from the sheet object and paste it into the module.

You might also want to remove references to Worksheets("local"), unless your
intent is to reference a worksheet that might not be the active worksheet.

And the use of ActiveSheet appears to be redundant, or it needs to be
changed, depending on your intent.

You might need to understand the distinction among the various ways to refer
to worksheets implicitly and explicitly.

Suppose the code is currently in the Sheet1 object, the ActiveSheet is
Sheet2, and the worksheet "local" is Sheet3. That is, there are three
different worksheets involved.

Then Range("W2") is equivalent to Sheet1.Range("W2"), ActiveSheet.Cells is
equivalent to Sheet2.Cells, and Worksheets("local").Cells is equivalent to
Sheet3.Cells.

If you simply cut-and-paste the code into a normal module without change,
Range("W2") will be equivalent to Sheet2.Range("W2"). All the other
equivalent references would be the same.