Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using two object variables

Hi there,

I would like to use two object variables that holds two seperate values, but
I don't seem to get it to work. The object 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 object
Dim d as object

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 the d-value........
I need to work with both the objects, how?.

Dim currentMonth as object
Dim d as object

Set currentMonth = Range("StartMonth:EndMonth").Find(Range("ReportMon th"),
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.
I could be working with strings instead of objects, but I don't know how when
I want to use the find method.

Take care,

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200707/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default Using two object variables

At first blush, I think I'd change object in these statements

Dim currentMonth as object
Dim d as object

to Range

HTH,
Barb Reinhardt

"Animal via OfficeKB.com" wrote:

Hi there,

I would like to use two object variables that holds two seperate values, but
I don't seem to get it to work. The object 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 object
Dim d as object

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 the d-value........
I need to work with both the objects, how?.

Dim currentMonth as object
Dim d as object

Set currentMonth = Range("StartMonth:EndMonth").Find(Range("ReportMon th"),
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.
I could be working with strings instead of objects, but I don't know how when
I want to use the find method.

Take care,

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200707/1


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Using two object variables

I would think your problem is here

Set currentMonth = Range("StartMonth:EndMonth").Find(Range("ReportMon th"),
LookIn:=xlValues)


assuming that StartMonth and EndMonth are two separate named cells.

Try

Set currentMonth =
Range(Range("StartMonth",Range("EndMonth")).Find(R ange("ReportMonth"),
LookIn:=xlValues)


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Animal via OfficeKB.com" <u33413@uwe wrote in message
news:751ce1ea8455e@uwe...
Hi there,

I would like to use two object variables that holds two seperate values,
but
I don't seem to get it to work. The object 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 object
Dim d as object

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 the d-value........
I need to work with both the objects, how?.

Dim currentMonth as object
Dim d as object

Set currentMonth = Range("StartMonth:EndMonth").Find(Range("ReportMon th"),
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.
I could be working with strings instead of objects, but I don't know how
when
I want to use the find method.

Take care,

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200707/1



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using two object variables

Nope , can not get it to work.......

--
Message posted via http://www.officekb.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Using two object variables

I had an error, should have been

Range(Range("StartMonth"),Range("EndMonth")).Find( Range("ReportMonth"),
LookIn:=xlValues)

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Animal via OfficeKB.com" <u33413@uwe wrote in message
news:75426d62db0ba@uwe...
Nope , can not get it to work.......

--
Message posted via http://www.officekb.com





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Using two object variables

I did what you said, but that is not the problem I guess. Because I still get
an error.
The problem occurs in the statement:

1.At first I SET the currentMonth variable
2. Then I SET the d variable (that is based in currentMonth)
3. Then I SET the currentMonth to look for the next value. Set currentMonth =
Range("StartMonth:EndMonth").FindNext (currentMonth). Here it becomes nothing
for some reason.
But when I delete step 2 in the code, everything is as it is supposed to be
and worked well. But as soon as I set the d variable, it doesn't work. Weared
isn't it?

Could someone please help me? It have taken me days to worke this problem out,
and I haven't come up for a solution yeat, puhhhh....

Thanks in advance!

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200707/1

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Using Range Object With Two Variables ALATL Excel Programming 2 June 6th 07 08:59 PM
Calling an Object using variables (What am I doing wrong????) Superman Excel Programming 2 May 2nd 07 05:25 PM
Object definition and structure, with variables Neal Zimm Excel Programming 6 February 24th 05 09:08 AM
Object variables scarbrough Excel Programming 3 December 6th 03 12:13 PM


All times are GMT +1. The time now is 09:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"