Closed Thread
Results 1 to 4 of 4

Range object drops it's value

  1. #1
    Registered User
    Join Date
    07-16-2007
    Posts
    2

    Range object drops it's value

    Hi there,

    I would like to use two range variables that holds two seperate values, but
    I don't seem to get it to work. The range variable seems to change as soons
    as the other object gets a value. Why? I have to work with two different
    values.
    I simplified my code to demonstrate:

    Dim c as range
    Dim d as range

    Set c = Range("A1:A10").Find(10, LookIn:=xlValues)
    Set d = Range("B1:B10").Find(2, LookIn:=xlValues)
    If Not c Is Nothing Then
    firstAddress = c.Address
    Do
    Set c = Range("A1:A10").FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
    End If

    --------------------------------------------------
    Here is my real code. I get an error when I come to the loop while and the
    currentMonth assigns a nothing value........
    I need to work with both the objects, how?.

    Dim currentMonth as range
    Dim d as range

    Set currentMonth = Range("StartMonth:EndMonth").Find(Range("ReportMonth"),
    LookIn:=xlValues)
    Set d = Range("Year", currentMonth.Offset(-1, 0)).Find(Range("ReportYear"),
    LookIn:=xlValues)
    If Not currentMonth Is Nothing Then
    firstAddress = currentMonth.Address
    Do
    If Not d Is Nothing Then
    FormatCurrentMonth
    Else
    Set currentMonth = Range("StartMonth:EndMonth").FindNext
    (currentMonth)
    Loop While Not currentMonth Is Nothing And firstAddress <>
    currentMonth.Address
    End If

    Could someone maybe help me.


    Take care,

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Animal,

    Welcome to the forum. Please read the rules below and then wrap your code

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Registered User
    Join Date
    07-16-2007
    Posts
    2

    How to hold two range variables

    Hi there,

    I would like to use two range variables that holds two seperate values, but
    I don't seem to get it to work. The range variable seems to change as soons
    as the other object gets a value. Why? I have to work with two different
    values.
    I simplified my code to demonstrate:

    Dim c as range
    Dim d as range

    Set c = Range("A1:A10").Find(10, LookIn:=xlValues)
    Set d = Range("B1:B10").Find(2, LookIn:=xlValues)
    If Not c Is Nothing Then
    firstAddress = c.Address
    Do
    Set c = Range("A1:A10").FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstAddress
    End If

    --------------------------------------------------
    Here is my real code. I get an error when I come to the loop while and the
    currentMonth assigns a nothing value........
    I need to work with both the objects, how?.

    Dim currentMonth as range
    Dim d as range

    Set currentMonth = Range("StartMonth:EndMonth").Find(Range("ReportMonth"),
    LookIn:=xlValues)
    Set d = Range("Year", currentMonth.Offset(-1, 0)).Find(Range("ReportYear"),
    LookIn:=xlValues)
    If Not currentMonth Is Nothing Then
    firstAddress = currentMonth.Address
    Do
    If Not d Is Nothing Then
    FormatCurrentMonth
    Else
    Set currentMonth = Range("StartMonth:EndMonth").FindNext
    (currentMonth)
    Loop While Not currentMonth Is Nothing And firstAddress <>
    currentMonth.Address
    End If

    Could someone maybe help me.


    Take care,

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Thread closed for not following rules.

    PM if you agree to the rules

    VBA Noob

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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