Find active cell

  • Thread starter Thread starter Thomas
  • Start date Start date
T

Thomas

New to Excel VBA. The following does not return the current active cell
but returns error 91.

Sub Macro1()
'
' Macro1 Macro
'
Dim rangeCurrentCell As Range
'
rangeCurrentCell = ActiveCell

'more stuff

The defn. of ActiveCell is confusing me. All I want is the currently
selected in A1 type format.

Thanks.

Thomas
 
Thomas, It lloks as if you are lloking for : ActiveCell.Address
This will return $H$7 if the cursor is on cell H7.

--
Regards,
Auk Ales

* Please reply to this newsgroup only *
* I will not react on unsolicited e-mails *
 
Thomas,

Object variables are assigned with the Set command

Set rangeCurrentCell = ActiveCell

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Perhaps I am being dense (wouldn't be the first time). However, this
code still gives the same error (Run time error '91': Object variable or
With block variable not set)

Sub Macro1()
'
' Macro1 Macro
'
Dim rangeCurrentCell As Range
'
rangeCurrentCell = ActiveCell.Address

' more stuff…

If fails at the rangeCurrentCell = ActiveCell.Address line.

The other solution, "Set rangeCurrentCell = ActiveCell" fails the same way.

What am I missing? This should not be that hard.

Thanks.

Best regards,

Thomas
 
Thomas,

You are mixing types up.

You declare rangeCurrentCell as a range, but then try to use it as a
variable and assign it a string value. This works

Dim rangeCurrentCell As String
'
rangeCurrentCell = ActiveCell.Address

I am also surprised to hear you say that

Set rangeCurrentCell = ActiveCell

it certainly works for me as long as rangeCurrentCell is declared as range
or variant.
--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
Oi! Thanks, Bob. Got off on the wrong track and couldn't see it. Not
sure about the rangeCurrentCell = ActiveCell. I will look further into it.

Thomas
 
Back
Top