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 6550603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:14:08+00:00 2026-05-25T12:14:08+00:00

I’m trying to dynamically transpose a Recordset over a Range in Excel using VBA.

  • 0

I’m trying to dynamically transpose a Recordset over a Range in Excel using VBA. I can do the transposition succesfully when I give it a static range such as this:

Range("A1:C16").Select
Range("A1:C16").Value = Application.WorksheetFunction.Transpose(scores)

When I try to use an equivalent string and pass it in to the Range function, however, it fails. My variable trange when printed out is “A1:C16” (including the double quotes). The reason I need to pass it a string is because the string is derived from a length variable which could be any value.

This code below fails:

Dim trange As String
trange = """A1:C" & slength & """"
MsgBox (trange)
Range(trange).Select
Range(trange).Value = Application.WorksheetFunction.Transpose(scores)

Unfortunately, escaping double quotes in VBA is ugly and that’s why my trange assignment expression looks strange but when I MsgBox it, it is in fact giving me the correct value.

  • 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-05-25T12:14:09+00:00Added an answer on May 25, 2026 at 12:14 pm

    Using string concatenation to construct range addresses is a bad idea. It’s messy and error-prone (as your example illustrates!).

    Instead of Range("A1:C16"), you can say any of the following:

    Range("A1").Resize(16, 3)
    Cells(1, 1).Resize(16, 3)
    Range(Cells(1, "A"), Cells(16, "C"))
    Range(Cells(1, 1), Cells(16, 3))
    

    There are probably more possibilities. The key is that none of them involve string concatenation.

    Replace 16 by slength in any of the examples above to make your variable-size range.

    Also, it’s good practice specify what worksheet you’re referring to. Instead of plain Range(anything), use e.g.

    Sheet1.Range(anything)
    Worksheets("Sheet1").Range(anything)
    

    or even better,

    With Sheet1
        .Range(anything)
        ' other stuff on Sheet1
    End With
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.