Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default How do I return the location (as a range) of ActiveCell?

I need the reference to a range to be dynamic, based on the ActiveCell. How
can I return the range of the ActiveCell so that I can use it in operations
requiring a Range as an argument?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10,124
Default How do I return the location (as a range) of ActiveCell?

?
ma=activecell.address

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Caeres" wrote in message
...
I need the reference to a range to be dynamic, based on the ActiveCell.
How
can I return the range of the ActiveCell so that I can use it in
operations
requiring a Range as an argument?


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default How do I return the location (as a range) of ActiveCell?

Thanks, just didn't know the syntax. I appreciate it.
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default How do I return the location (as a range) of ActiveCell?

Okay, scratch that, I'm still making some mistake. Here's the code I've got:

MsgBox ActiveCell.Address
Dim ActiveLoc As Range
ActiveLoc = ActiveCell.Address
[ActiveRange:N3].Select
ActiveRange.Activate
ActiveWorkbook.Worksheets("D-11 O.F.").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("D-11 O.F.").Sort.SortFields.Add
Key:=Range("ActiveRange"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("D-11 O.F.").Sort
.SetRange Selection.Range
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

The MsgBox line returns $A$6, so I know .Address is the right syntax, but
after the message box I get an error message: "Run-time error '91': Object
variable or With block variable not set" and the third line is highlighted in
the debugger. Hovering over it, I get the bubbles "ActiveLoc = Nothing" and
"ActiveCell.Address = $A$6". So something's going wrong with the assignment
of the range value to the variable, but I don't know why. Help?
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default How do I return the location (as a range) of ActiveCell?

Dim ActiveLoc As String

I don't know what the next line does but the above change will get you
there.


Gord Dibben MS Excel MVP

On Mon, 6 Oct 2008 07:43:02 -0700, Caeres
wrote:

Okay, scratch that, I'm still making some mistake. Here's the code I've got:

MsgBox ActiveCell.Address
Dim ActiveLoc As Range
ActiveLoc = ActiveCell.Address
[ActiveRange:N3].Select
ActiveRange.Activate
ActiveWorkbook.Worksheets("D-11 O.F.").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("D-11 O.F.").Sort.SortFields.Add
Key:=Range("ActiveRange"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("D-11 O.F.").Sort
.SetRange Selection.Range
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

The MsgBox line returns $A$6, so I know .Address is the right syntax, but
after the message box I get an error message: "Run-time error '91': Object
variable or With block variable not set" and the third line is highlighted in
the debugger. Hovering over it, I get the bubbles "ActiveLoc = Nothing" and
"ActiveCell.Address = $A$6". So something's going wrong with the assignment
of the range value to the variable, but I don't know why. Help?


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
ACTIVECELL LOCATION kt(uk) Excel Discussion (Misc queries) 2 September 12th 08 01:03 PM
If activecell.column = variable then activecell,offset (0,1) Battykoda via OfficeKB.com Excel Discussion (Misc queries) 1 October 2nd 07 08:05 PM
ActiveCell in a Range? Filo Excel Discussion (Misc queries) 3 May 22nd 07 09:52 PM
Activecell, not for cell,but for range? mturner Excel Discussion (Misc queries) 1 January 24th 06 04:55 PM
ActiveCell.Copy Range("R3C27") Stuart Grant New Users to Excel 2 September 30th 05 09:00 AM


All times are GMT +1. The time now is 01:49 PM.

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

About Us

"It's about Microsoft Excel"