+ Reply to Thread
Results 1 to 5 of 5

Relative Selection

  1. #1
    Registered User
    Join Date
    07-31-2019
    Location
    South Carolina
    MS-Off Ver
    Office 13
    Posts
    4

    Relative Selection

    I have a function that creates a copy of the current worksheet, renames the worksheet to the current date (MMM-YY) and changes volatile functions in certain cells to static functions to effectively freeze the data or create a snapshot. The range for the data that needs to be frozen is S8:S300.

    The worksheet formula is as follows:

    S8=INT((TODAY()-R8)/30.14) where R8 is the Start Date for an individual. This spits out an integer value for how many months a person has been in a position.

    I need my VBA sub to replace the above function with a static integer. Where S8 references R8, S10 references R10, and so on and so forth all the way to S300. Below is a copy of my "Freeze Data" sub that attempts to do this. Since I'm using a variable that does the calculation I don't know how to reference multiple ranges relative to the output ranges. I have also attached the excel sheet if any 42A's out there are lurking and want a graphical leader slate.

    Please Login or Register  to view this content.
    Any help would be appreciated. Apologies if this has been covered already as I am unsure of how to really describe the problem.
    Attached Files Attached Files
    Last edited by Pepper_; 08-02-2019 at 03:40 PM. Reason: Spelling

  2. #2
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Re: Relative Selection

    Check these out:
    https://docs.microsoft.com/en-us/off...cel.range.copy
    https://docs.microsoft.com/en-us/off...e.pastespecial

    So, it seems to me that you want to first Copy the R8:R300 range and the PasteSpecial (with the xlPasteValues option).

    Here is a tip. Use 'Record Macros' to auto generate the code on how to do something you do manually. You probably know how to do this with various button clicks and selections. Recording a macro will usually get you on the right path (although it is usually not the most dynamic or efficient code).
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: Relative Selection

    Untested, but try:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    07-31-2019
    Location
    South Carolina
    MS-Off Ver
    Office 13
    Posts
    4

    Re: Relative Selection

    TMS,

    This just makes the S column equal to the R column. I need to incorporate the R reference into the equation. For example

    S8=(Date - Worksheets("MAIN SLATE").Range("R8")) / 30.14
    S10=(Date - Worksheets("MAIN SLATE").Range("R10")) / 30.14
    S12=(Date - Worksheets("MAIN SLATE").Range("R12")) / 30.14

    So on and so forth.

  5. #5
    Registered User
    Join Date
    07-31-2019
    Location
    South Carolina
    MS-Off Ver
    Office 13
    Posts
    4

    Re: Relative Selection

    Read a book about VBA and found how useful the R1C1 is:

    Please Login or Register  to view this content.

+ 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. Listbox selection relative to last row
    By Biffer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2015, 05:43 AM
  2. [SOLVED] Relative Selection based on column to the left
    By Shawn Michaels in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-06-2012, 12:12 PM
  3. [SOLVED] Relative Range Selection
    By Ashali in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-02-2012, 04:07 AM
  4. VBA range Selection with relative reference
    By clemsoncooz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-29-2011, 12:39 PM
  5. Selection.CellTypeVisible Relative Cell Value
    By ron_oniel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-07-2011, 07:16 PM
  6. Macro relative range selection
    By griz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-02-2008, 05:12 AM
  7. Need to delete rows relative to selection
    By ratchick in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-22-2005, 12:55 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