LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.newusers
external usenet poster
 
Posts: 829
Default Macro Help

"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.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro to copy and paste values (columns)I have a macro file built C02C04 Excel Programming 2 May 2nd 08 01:51 PM
Macro not showing in Tools/Macro/Macros yet show up when I goto VBA editor [email protected] Excel Programming 2 March 30th 07 07:48 PM
Need syntax for RUNning a Word macro with an argument, called from an Excel macro Steve[_84_] Excel Programming 3 July 6th 06 07:42 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 07:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"