Results 1 to 6 of 6

Declaring variables

Threaded View

  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.

        Dim LastRow As Long
        Dim i As Long
        Dim RangeOne As Long
        Dim RangeTwo As Long
    
        LastRow = Cells(Rows.Count, "BF").End(xlUp).row
    
        For i = 3 To LastRow
            If Range("BE" & i).Value <> "" And Range("BD" & i - 1) > 1 And Range("BK" & i - 1) <> "" Then
                Range("BG" & i, "BN" & i).Value = Range("BK" & i - 1, "BR" & i - 1).Value
            End If
        Next i

    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?

        Dim LastRow As Long
        Dim i As Long
        Dim RangeOne As Long
        Dim RangeTwo As Long
    
        LastRow = Cells(Rows.Count, "BF").End(xlUp).row
        RangeOne = Range("BG" & i, "BN" & i)
        RangeTwo = Range("BK" & i - 1, "BR" & i - 1)
    
        For i = 3 To LastRow
            If Range("BE" & i).Value <> "" And Range("BD" & i - 1) > 1 And Range("BK" & i - 1) <> "" Then
                RangeOne.Value = RangeTwo.Value
            End If
        Next i
    Last edited by hei.so; 01-16-2018 at 09:27 AM.

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