+ Reply to Thread
Results 1 to 4 of 4

Copy range of cells using variable criteria and named ranges

  1. #1
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Copy range of cells using variable criteria and named ranges

    I am trying to write some simple VBA that will find a range of cells on one worksheet, to go to another worksheet to paste values of that range based on another range of cells.

    The method I’d like to adopt to reference the ranges is Range(Cells(R,C)),as it seems to provide the flexibility I need for the ranges, which may change. Additionally, I am using Named Ranges where I can in order to preserve references should rows or columns shift in the evolution of my spreadsheet.

    That said, I’d like to: 1) Find an anchor cell [Named Range1], which is the upper left of the range; 2) Select the range where R = Named Range2, and C = Named Range1’s column value + Named Range3. For instance, Named Range1’s address is $B$5, Named Range2 = 11, and Named Range3 = 6. The goal is that the selected range for this example is $B$5:$G$15. If any of these Named Ranges [variables] change, the resulting selected range will change. Each of the named ranges are scoped to the workbook. Once the range is selected, I would like the macro to go to a second anchor [Named Range4], and paste values.

    I’ve tried searching for an answer to this, found many similar questions, but my complete lack of programming skill and ignorance of VBA syntax and lexicon has just stopped me from gaining any traction. Without even attempting to code.

    Any help the community can provide will I’m sure be invaluable.
    Book1.xlsx

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Copy range of cells using variable criteria and named ranges

    Hi, Cpetersoc,

    if you mention Named Ranges you better include all of them in your workbook (Named_Range_Last_Row is missing).

    Maybe try
    Please Login or Register  to view this content.
    where you could substitute the number 11 by the range name if you included that as well in the workbook.

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copy range of cells using variable criteria and named ranges

    This was very helpful getting me started. I didn't quite understand the function/purpose of the If statement - so I made the changes below, and everything appears to be working as I need it to. I added some formatting commands just to test if everything was working...Thanks for your help!

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-12-2012
    Location
    Miami, Florida
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Copy range of cells using variable criteria and named ranges

    Here is the spreadsheet as revisedBook1.xlsm

+ 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. Insert comments using data from cells in variable, named ranges
    By horariatersenha in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-13-2014, 04:22 PM
  2. Looping Mutliple Named Resized Ranges in next empty row below another named range
    By gingumdog in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-19-2014, 08:15 PM
  3. Create a named range of cells BUT variable in reference to a cell value
    By peponfree in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 02-13-2014, 12:46 PM
  4. [SOLVED] Using Named Ranges to allow for Inserting Cells Within a VBA Coded Range
    By timmymckinney in forum Excel Programming / VBA / Macros
    Replies: 26
    Last Post: 06-27-2013, 11:51 AM
  5. Copy & paste from cells below named ranges
    By Glio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-19-2007, 08:15 AM

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