+ Reply to Thread
Results 1 to 6 of 6

How to Swap Variable Ranges?

  1. #1
    Registered User
    Join Date
    06-19-2017
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    33

    How to Swap Variable Ranges?

    Writing a macro that necessitates swapping ranges (but not entire rows). I need to swap ranges("i2:i19") and ranges("'i-1'2:'i-1'19") where i is a variable in a for loop that is iterating. How do I do this?

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to Swap Variable Ranges?

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,601

    Re: How to Swap Variable Ranges?

    What is range("'i-1'2:'i-1'19")
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    06-19-2017
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    33

    Re: How to Swap Variable Ranges?

    i is a variable that loops through a for loop and corresponds with a row number

  5. #5
    Registered User
    Join Date
    06-19-2017
    Location
    Texas
    MS-Off Ver
    2013
    Posts
    33

    Re: How to Swap Variable Ranges?

    Quote Originally Posted by mehmetcik View Post
    Please Login or Register  to view this content.
    Tried this but it doesn't work. It throws an error at the last line.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,601

    Re: How to Swap Variable Ranges?

    Quote Originally Posted by mumair View Post
    i is a variable that loops through a for loop and corresponds with a row number
    No it's not. You have i inside single quotes inside double quotes. That's not VBA syntax. I'm trying to get you to explain your calculation in words. Post the whole code.

    For instance, the i in: range("i2:i19") is not a variable. If you have a line:
    Dim i
    in your code somewhere, it has absolutely nothing to do with Range("i2")
    Last edited by protonLeah; 06-20-2017 at 05:53 PM.

+ 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. Swap ranges within the same row
    By JWil408 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-08-2015, 09:24 AM
  2. Swap Two Cell Ranges?
    By papagorgio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2010, 01:46 PM
  3. Variable Ranges - VBA - Help!
    By MelissaJordan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-20-2010, 07:22 AM
  4. Swap identical ranges of cell values
    By CCArtsAlliance in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-25-2010, 10:54 PM
  5. [SOLVED] Counting variable ranges and auto-summing variable ranges
    By Father Guido in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2006, 11:10 PM
  6. Variable ranges
    By John Contact in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  7. Variable ranges
    By John Contact in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 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