Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 4
Default Define Object Variable

Hi All,
This seems to be a so simple problem, but i can't figure it out.
Here is my code im using:

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub

When i run that code, i get a Run-Time error '91':
Object Variable or With variable block not set

If i use:
Set r = ActiveCell.Address
instead of: r = ActiveCell.Address
then i get Type Mismatch error.

Can someone please help.

Cheers.
Albert


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Define Object Variable

Hi Al,

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub


Make that:

Set r = ActiveCell.Address

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Define Object Variable

Typo?
Are you sure you dont mean:
Set r = ActiveCell

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Jan Karel Pieterse" wrote in message
...
Hi Al,

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub


Make that:

Set r = ActiveCell.Address

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 535
Default Define Object Variable

Hi Rob,

Are you sure you dont mean:
Set r = ActiveCell


Of course I did, who added that silly .address to it ?

<bg

Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Define Object Variable

You're mixing types.

The Address property returns a string.
Use set when you want to reference an object.

This example may help.

Sub test()
Dim str As String, rng As Range

Set rng = ActiveCell
MsgBox rng.Address

str = ActiveCell.Address
MsgBox str

Set rng = Range(str)
MsgBox rng.Value
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"al" wrote in message
...
Hi All,
This seems to be a so simple problem, but i can't figure it out.
Here is my code im using:

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub

When i run that code, i get a Run-Time error '91':
Object Variable or With variable block not set

If i use:
Set r = ActiveCell.Address
instead of: r = ActiveCell.Address
then i get Type Mismatch error.

Can someone please help.

Cheers.
Albert






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 430
Default Define Object Variable

Ron:
#3 <<below is returning a value, not the address property.
Was that intentional?
#1 and #2 are OK..

Set rng = Range(str)
MsgBox rng.Value

Thanks for all your help..
JM


"Rob van Gelder" wrote in message
...
You're mixing types.

The Address property returns a string.
Use set when you want to reference an object.

This example may help.

Sub test()
Dim str As String, rng As Range

Set rng = ActiveCell
MsgBox rng.Address

str = ActiveCell.Address
MsgBox str

Set rng = Range(str)
MsgBox rng.Value
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"al" wrote in message
...
Hi All,
This seems to be a so simple problem, but i can't figure it out.
Here is my code im using:

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub

When i run that code, i get a Run-Time error '91':
Object Variable or With variable block not set

If i use:
Set r = ActiveCell.Address
instead of: r = ActiveCell.Address
then i get Type Mismatch error.

Can someone please help.

Cheers.
Albert






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Define Object Variable

Yes, intentional.

My point was that once you have the range object, you can return whichever
property you want.

I could have also written MsgBox rng.Address

--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Jim May" wrote in message
news:J3W9d.34289$a85.26039@fed1read04...
Ron:
#3 <<below is returning a value, not the address property.
Was that intentional?
#1 and #2 are OK..

Set rng = Range(str)
MsgBox rng.Value

Thanks for all your help..
JM


"Rob van Gelder" wrote in message
...
You're mixing types.

The Address property returns a string.
Use set when you want to reference an object.

This example may help.

Sub test()
Dim str As String, rng As Range

Set rng = ActiveCell
MsgBox rng.Address

str = ActiveCell.Address
MsgBox str

Set rng = Range(str)
MsgBox rng.Value
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"al" wrote in message
...
Hi All,
This seems to be a so simple problem, but i can't figure it out.
Here is my code im using:

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub

When i run that code, i get a Run-Time error '91':
Object Variable or With variable block not set

If i use:
Set r = ActiveCell.Address
instead of: r = ActiveCell.Address
then i get Type Mismatch error.

Can someone please help.

Cheers.
Albert








  #8   Report Post  
Posted to microsoft.public.excel.programming
al al is offline
external usenet poster
 
Posts: 4
Default Define Object Variable

Thank you both.
I did get confused Jan's reply, but i managed to work it out.
The joys of being thrown into the deep-end.

Again, thank you both for your help.

Cheers.
Al


"al" wrote in message
...
Hi All,
This seems to be a so simple problem, but i can't figure it out.
Here is my code im using:

Sub test()
Dim r As Range
r = ActiveCell.Address
MsgBox r
Exit Sub

When i run that code, i get a Run-Time error '91':
Object Variable or With variable block not set

If i use:
Set r = ActiveCell.Address
instead of: r = ActiveCell.Address
then i get Type Mismatch error.

Can someone please help.

Cheers.
Albert




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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
Object Variable Not Set Error on Selection object Jean Excel Worksheet Functions 3 July 24th 06 06:45 PM
Application-Defined or Object Define error? Help please. NooK[_58_] Excel Programming 2 August 12th 04 08:59 AM
Cells.Find error Object variable or With block variable not set Peter[_21_] Excel Programming 2 May 8th 04 02:15 PM
Pivot Table - Object variable or with block variable not set? George Nicholson[_2_] Excel Programming 1 April 16th 04 09:12 PM


All times are GMT +1. The time now is 11:31 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"