Results 1 to 3 of 3

Thread: [RESOLVED] Why don't we use double quotes when working with variables?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    7

    Resolved [RESOLVED] Why don't we use double quotes when working with variables?

    Hi, while writing a cell address in a range object I need to use double quotes
    example: range("B5").select
    But when I use variables for defining an address I don't require double quotes
    example: range(x & y).select
    Here x is a string and y is an integer

    Can someone please explain why range("x & y") not valid since we are required to use double quotes as a convention?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Why don't we use double quotes when working with variables?

    This is pretty basic stuff that you really shouldn't need explaining because it's covered by beginner tutorials. Double quotes denote a literal String value. The only thing you wrap in double quotes is literal text. An expression that concatenates two variables is not literal text so it doesn't go in double quotes. This:
    vb Code:
    1. range("B5").select
    would be the equivalent of doing this:
    vb Code:
    1. Dim var As String = "B5"
    and then using this:
    vb Code:
    1. range(var).select
    The argument needs to be a String containing the name of a valid range. That String can be a literal or a variable or some other expression that evaluates to a String, e.g. the concatenation of two other variables.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2021
    Posts
    7

    Re: Why don't we use double quotes when working with variables?

    Thank you for the detailed explanation. I am new to programming and learning it from Coursera. I will make sure to check other basic tutorials next time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width