Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8832073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:27:00+00:00 2026-06-14T08:27:00+00:00

I have a string passed to a VBA sub, which is of the format

  • 0

I have a string passed to a VBA sub, which is of the format “Sheet1:Sheet5!A1:D10”, referring to a range across several worksheets in the same workbook (Sheet2, Sheet3 and Sheet4 are between Sheet1 and Sheet5).

The problem I have is that I cannot apply this reference to a range variable, which as far as I can tell is due to the multiple references, and I cannot use application.union since the ranges are on different sheets.

How can I extract from this string the five individual ranges of Sheet1!A1:D10, Sheet2!A1:D10 and so on?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:27:01+00:00Added an answer on June 14, 2026 at 8:27 am

    This will get you the string representations of each one and then store in an array. It makes a few assumptions (that the sheets exist, that the first one listed is first in the index order, that you want everything between the two with regards to index. etc.), but it may work for your situation:

    Sub Parse()
    
        Dim wbk As Workbook
        ' Arbitrary array size of 10 to store the ranges (as an example)
        Dim myRanges(10) As Variant
    
        Set wbk = ActiveWorkbook
    
        ' Split the string at the !
        s = "Sheet1:Sheet3!A1:D10"
        s = Split(s, "!")
    
        ' Range is the second element of the split (A1:D10)
        TargetRange = s(1)
    
        ' The first contains the sheets, so split on the :
        SheetNames = Split(s(0), ":")
    
        ' These sheets are the lower/upper bounds, so use their indices in a loop
        ' that cycles over the sheets in between them (inclusive)
        j = 0 ' This is for the array - you may not need it
        For i = wbk.Sheets(SheetNames(0)).Index To wbk.Sheets(SheetNames(1)).Index
          ' Range is the concatenation of the sheet at this index and the target range
          Set Rng = Range(wbk.Sheets(i).Name & "!" & TargetRange)
          ' Drop it in to our array (or handle how you want)
          myRanges(j) = Rng
          j = j + 1
        Next i
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JS function which is passed a string that a RegEx is
I have a string that I want passed via the linebreaks filter. {% trans
I have a string in KOI8-R encoding, it's passed as argv, so initially it's
I have been passed a date string that looks like this: Thu%20Mar%2011%202010%2015%3A09%3A11%20GMT%2B0000%20(BST) I want
I have a very basic query string which passes a ID to a receiving
I have a string that is passed by parameter and I have to replace
I have a function that gets a string passed to it. When testing the
I have to make sure that a string passed as argument does not cause
Possible Duplicate: how to evaluate formula passed as string in php? I have a
I have several string each containing a JSON representation of an array of objects.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.