+ Reply to Thread
Results 1 to 5 of 5

Range issues inside macro

  1. #1
    Registered User
    Join Date
    11-08-2004
    Posts
    41

    Range issues inside macro

    Hi All,

    I made a macro that extends my sheet by adding borders to two new rows. It works as long as the new cells (range) are hard-coded, but when I try using variables to define the range it throws errors. This is a small test sheet that I've been trying to get to work, I will upload it in full.

    Here's what I'm seeing. In the pic, the error shows my range object with double quotes while the debug window shows the expected single quotes. If I copy the exact line from the DB window and paste it into my range (), the code works.

    macro quotes.jpg

    And here's "test.xls" for your scrutiny.

    Russ
    Attached Files Attached Files
    Last edited by RASelkirk; 04-04-2022 at 02:19 PM. Reason: solved

  2. #2
    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,463

    Re: Range issues inside macro

    Just myRange = firstCol & lastCol
    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


  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Range issues inside macro

    try

    Set myRange = Range(firstcol & lastcol)

    and

    myRange.Select
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Registered User
    Join Date
    11-08-2004
    Posts
    41

    Re: Range issues inside macro

    Quote Originally Posted by TMS View Post
    Just myRange = firstCol & lastCol
    Doh! That must have been the one iteration I failed to try. Works perfect, no quotes required.

    Russ

  5. #5
    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,463

    Re: Range issues inside macro

    You're welcome.

+ 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. Collection inside a class, issues retrieving data
    By bennett4455 in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 07-23-2015, 06:16 AM
  2. First Macro Issues: Range selection
    By skcuf in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-20-2014, 07:44 PM
  3. Function inside Macro that move a range rows if cells are used
    By oguilamo in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 08-29-2012, 11:51 PM
  4. Modifying named range fails inside macro but succeeds when continued
    By krzcho in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-14-2012, 04:02 AM
  5. Macro that runs inside cell range selected
    By TrentSe7en in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-06-2010, 05:41 AM
  6. referencing range elements inside the macro
    By Greg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-03-2006, 09:10 PM
  7. Macro Range issues (I think)
    By tmann in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 11-24-2005, 04:23 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