Results 1 to 6 of 6

How to use macros that can work on different Worksheets

Threaded View

  1. #1
    Registered User
    Join Date
    09-02-2016
    Location
    Brooklyn, NY
    MS-Off Ver
    7
    Posts
    11

    How to use macros that can work on different Worksheets

    I'm pretty novice at programming Macros and coding VB so this is must be very basic question but I can't figuring it out by myself. I have recorded a Macro that moves and arranges some cells around my worksheet .it works wonderful until I tried to apply this Macro on another worksheet and then it stopped working right were the file name of the previous document was. My question is how to replace the filename in the macro with a veritable or current worksheet statement so it will work always with every file that I want.

    Example:

    Range("P2:P240").Select
        ActiveWorkbook.Worksheets("Download (6)").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Download (6)").Sort.SortFields.Add Key:=Range("P2" _
            ), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Download (6)").Sort
            .SetRange Range("A2:AT17")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    Last edited by JBeaucaire; 03-26-2017 at 05:28 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macros to work in all worksheets
    By bigband1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-16-2016, 09:58 AM
  2. Macros stop to work when work sheet is protected. Run time error 1004
    By sellim in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-18-2012, 01:14 AM
  3. [SOLVED] How to globally get Macros to work around "Protected" /Locked Worksheets and Workbooks
    By nenadmail in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 05-23-2012, 03:21 AM
  4. [SOLVED] deleting worksheets from a file which has macros in it........does not work.
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-17-2012, 12:56 PM
  5. Macros to work on individual worksheets
    By thunder-foot in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-23-2009, 12:43 PM
  6. [SOLVED] Getting embeded Excel worksheets with macros in Word to work
    By dwight.yorke@gmail.com in forum Excel General
    Replies: 3
    Last Post: 06-20-2006, 02:35 PM
  7. [SOLVED] Getting embeded Excel worksheets with macros in Word to work
    By dwight.yorke@gmail.com in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-19-2006, 11:50 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1