+ Reply to Thread
Results 1 to 2 of 2

VBA Variable as a Range (A1:A100)

  1. #1
    Registered User
    Join Date
    04-08-2016
    Location
    California
    MS-Off Ver
    windows 7
    Posts
    28

    VBA Variable as a Range (A1:A100)

    Hi All,

    I am wondering if there is anyway to set a variable as a range.

    This is what I have

    Sub Macro ()
    Dim rng As String

    rng = "A2:A100"

    If (rng = "Power Group Overhead") Then
    Range("A2:A100").Value = 1
    Else
    Range("A2:A100").Value = 2
    End If

    End Sub

    Whenever I run this code, all I get is 2, but there is "Power Group Overhead". So the answer should be a mix of 1 and 2.

    Thanks All
    Attached Files Attached Files

  2. #2
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA Variable as a Range (A1:A100)

    Your Else will always be True since the String value "A2:A100" is never equal to the String value "Power Group Overhead".

    If your intent was to check each cell in the range then a loop can be used. e.g.
    Please Login or Register  to view this content.

+ 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. [SOLVED] copy range A4:A100 and paste on another workbook's sheet but one by one
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-01-2014, 08:11 AM
  2. [SOLVED] when updating sheet1 a1:a100, auto updates sheet2 a1:a100.
    By chestersneakers7 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-15-2013, 08:09 AM
  3. [SOLVED] Prvent Duplicates in Range A2:A100 while coping in to another sheet
    By vaibhav2312 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 08-21-2012, 09:22 AM
  4. Variable Cell Reference, A(B10):A100
    By afguy2011 in forum Excel General
    Replies: 5
    Last Post: 03-12-2012, 01:43 PM
  5. Formula A1:A100 - how to determine range by B1's value instead?
    By booost in forum Excel - New Users/Basics
    Replies: 6
    Last Post: 10-20-2011, 05:04 AM
  6. Replies: 5
    Last Post: 03-22-2010, 01:35 PM
  7. Range Value ie: (A1:A100) The Option of?
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-09-2005, 05:38 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