+ Reply to Thread
Results 1 to 6 of 6

Declaring variables

  1. #1
    Registered User
    Join Date
    11-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2011
    Posts
    15

    Declaring variables

    Is there a way to declare variables in excel? I have a simple copy and paste macro here.

    Please Login or Register  to view this content.

    I defined my range in the loop as RangeOne and RangeTwo so it becomes something like this but it is giving me an error. I know I can name cells out of the editor but is there another way?

    Please Login or Register  to view this content.
    Last edited by hei.so; 01-16-2018 at 09:27 AM.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: Declaring variables

    Range is an object. So you need to "Set" variable.
    Ex.
    Please Login or Register  to view this content.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    11-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2011
    Posts
    15

    Re: Declaring variables

    Do I have to use rng? I use rangeOne and rangeTwo because I have two different ranges. But this is still giving me error 1004.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,882

    Re: Declaring variables

    Oh, should have looked at your Range argument closer. You can't use "BG#", "BN#" in range.

    Should be.. Range("BG" & i & ":BN" & i)

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Declaring variables

    Should these 2 lines of code be inside the loop?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Registered User
    Join Date
    11-07-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2011
    Posts
    15

    Re: Declaring variables

    Quote Originally Posted by CK76 View Post
    Oh, should have looked at your Range argument closer. You can't use "BG#", "BN#" in range.

    Should be.. Range("BG" & i & ":BN" & i)
    Still doesn't work. Not sure what I'm doing wrong but at this point, I will look at it later for learning purposes. The code works with not declaring variables.


    Quote Originally Posted by Norie View Post
    Should these 2 lines of code be inside the loop?
    Please Login or Register  to view this content.
    I entered it in the For loop but for some reason it messes up other parts of my code. I'll leave it for now.

    Thanks to you both.

+ 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. Declaring variables
    By sdgenxr in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-05-2017, 09:21 PM
  2. [SOLVED] Declaring Variables
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-16-2014, 01:45 PM
  3. [SOLVED] declaring variables help
    By jakeembx in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-14-2013, 04:03 PM
  4. Declaring Variables - Why?
    By The Drone in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-02-2012, 09:01 AM
  5. Declaring Variables
    By Weston33 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-06-2012, 05:39 AM
  6. Declaring of variables
    By pspyve in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-08-2011, 08:44 PM
  7. Declaring variables
    By freekrill in forum Excel General
    Replies: 2
    Last Post: 07-19-2006, 01:36 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