+ Reply to Thread
Results 1 to 7 of 7

Reference active worksheet

  1. #1
    Registered User
    Join Date
    03-17-2008
    Location
    UK
    MS-Off Ver
    365 online
    Posts
    20

    Reference active worksheet

    I have some code to sort a column on the active worksheet. But the code currently specifies the worksheet name. How can I get it to reference the active worksheet instead, so I can use with any filename?

    Please Login or Register  to view this content.
    Thanks,

    Jon

  2. #2
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,874

    Re: Reference active worksheet

    Try this (Untested)

    Please Login or Register  to view this content.
    Last edited by NeedForExcel; 02-29-2016 at 07:40 AM.
    Cheers!
    Deep Dave

  3. #3
    Registered User
    Join Date
    03-17-2008
    Location
    UK
    MS-Off Ver
    365 online
    Posts
    20

    Re: Reference active worksheet

    It didn't sort it. I want to sort the O column. I tried Range("O2") instead to see if that made any difference and it didn't.

  4. #4
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,874

    Re: Reference active worksheet

    Try this

    Please Login or Register  to view this content.
    Last edited by NeedForExcel; 02-29-2016 at 08:05 AM.

  5. #5
    Registered User
    Join Date
    03-17-2008
    Location
    UK
    MS-Off Ver
    365 online
    Posts
    20

    Re: Reference active worksheet

    NeedForExcel, I tried that but it didn't work. O1 is a header if that makes and difference and the top row has an AutoFilter. The strange thing is that after the main part of the macro runs, I can quite easily manually do the sort. But not via VBA,

    If I select a cell O2, I can apply a sort manually. But if I select the entire column, it says Microsoft Excel found data next to your select. Then you have an Expand your selection option. Not sure if that gives clues?

  6. #6
    Forum Expert NeedForExcel's Avatar
    Join Date
    03-16-2013
    Location
    Pune, India
    MS-Off Ver
    Excel 2016:2019, MS 365
    Posts
    3,874

    Re: Reference active worksheet

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

  7. #7
    Registered User
    Join Date
    03-17-2008
    Location
    UK
    MS-Off Ver
    365 online
    Posts
    20

    Re: Reference active worksheet

    I have attached the csv file and my code is:

    Please Login or Register  to view this content.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 07-03-2015, 04:27 AM
  2. Replies: 1
    Last Post: 07-07-2014, 09:19 AM
  3. Macro with reference to active chart on active sheet
    By bhavikpatel in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2014, 10:43 AM
  4. Replies: 3
    Last Post: 02-27-2014, 02:31 PM
  5. Selecting an active worksheet AND an active table that keep changing names!
    By brucemc777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-12-2014, 10:22 PM
  6. Macro to edit active chart on active worksheet
    By shlurpee in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2011, 04:58 AM
  7. Altering code to reference the worksheet before the active worksheet
    By KimberlyC in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-15-2005, 07:06 PM

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