+ Reply to Thread
Results 1 to 4 of 4

Selecting multiple ranges using variable

Hybrid View

  1. #1
    Registered User
    Join Date
    02-21-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2010
    Posts
    51

    Selecting multiple ranges using variable

    Hi all,

    I have a sheet that I copy various columns from and I had been using the row count as a large static value. I'm now checking how much data is there (no need trying to import something that is empty) for have the row count of data.

    The below is my the static and my changed variable statements (plus how I set my variable).

    However, when I run my macro it says "Wrong number of arguments or invalid property assignment". When I reduce to one column range, "B", it works then adding a second, "H", column range it copies all coloumns from B to H, not B and H. Adding all column ranges I get the error message above.

    Any ideas?



    Dim CheckRawData
    CheckRawData = Cells(Rows.Count, "B").End(xlUp).Row
    
    Range("B2:B20000,H2:H20000,J2:J20000,S2:U20000").Copy
    
    Range("B2:B" & CheckRawData, "H2:H" & CheckRawData, "J2:J" & CheckRawData).Copy

  2. #2
    Registered User
    Join Date
    02-21-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Selecting multiple ranges using variable

    Solved it....needed to quote the seperation "," in

    Range("B2:B" & CheckRawData & "," & "H2:H" & CheckRawData & "," & "J2:J" & CheckRawData & "," & "S2:U" & CheckRawData).Copy

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Selecting multiple ranges using variable

    Similar

    Range("B2:B" & CheckRawData & ", H2:H" & CheckRawData & ", J2:J" & CheckRawData & ",  S2:U" & CheckRawData).Copy

  4. #4
    Registered User
    Join Date
    02-21-2013
    Location
    Reading, England
    MS-Off Ver
    Excel 2010
    Posts
    51

    Re: Selecting multiple ranges using variable

    Thanks. Makes sense...certainly cleaner. Will change to what you've suggested.

    Quote Originally Posted by AB33 View Post
    Similar

    Range("B2:B" & CheckRawData & ", H2:H" & CheckRawData & ", J2:J" & CheckRawData & ",  S2:U" & CheckRawData).Copy

+ 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. selecting multiple ranges-scrool through the list
    By KRAND in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2011, 09:11 AM
  2. Selecting Multiple Data Ranges
    By dagindi in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-28-2010, 01:59 PM
  3. Selecting multiple dynamic ranges.
    By VoodooChild in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2010, 08:32 AM
  4. Selecting multiple ranges
    By F6Hawk in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-22-2008, 02:22 AM
  5. Selecting multiple ranges with a macro
    By Sudheerp in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2007, 08:11 AM
  6. Trouble with selecting multiple ranges of data
    By markag in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-23-2006, 11:40 AM
  7. [SOLVED] Selecting multiple ranges
    By john@fairstead.net in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2006, 02:50 PM
  8. [SOLVED] selecting multiple ranges
    By Helen in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-16-2005, 12:06 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