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 use the .Cells property to refer to ActiveCell?

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default How do I use the .Cells property to refer to ActiveCell?

Your request does not really make a lot of sense??? The active cell is a
single cell on the active sheet. Are you trying to define a range based off
of the active cell???

MsgBox Cells(ActiveCell.Row, ActiveCell.Column).Address
MsgBox Cells(ActiveCell.Row + 5, ActiveCell.Column).Address
MsgBox ActiveCell.Offset(5, 0).Address
MsgBox ActiveCell.Resize(6, 1).Address

--
HTH...

Jim Thomlinson


"Caeres" wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 154
Default How do I use the .Cells property to refer to ActiveCell?

Caeres,

The way to do this would be to place the following code into the script.

Cells(ActiveCell.Row, ActiveCell.Column)

--
--Thomas [PBD]
Working hard to make working easy.
Answered your question? Click ''''Yes'''' below.


"Caeres" wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How do I use the .Cells property to refer to ActiveCell?

maybe...

dim myRng as range
with activecell
set myrng = .parent.range(.cells(.row,.column).address)
end with

But that seems very convoluted to me. Why can't you just use Activecell?

Caeres wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 5,939
Default How do I use the .Cells property to refer to ActiveCell?

I just saw your other post. Try to stick 1 post to make life easy...

range(ActiveCell, range("N3")).Select

Selects a rectangle from the active cell through N3...

--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

Your request does not really make a lot of sense??? The active cell is a
single cell on the active sheet. Are you trying to define a range based off
of the active cell???

MsgBox Cells(ActiveCell.Row, ActiveCell.Column).Address
MsgBox Cells(ActiveCell.Row + 5, ActiveCell.Column).Address
MsgBox ActiveCell.Offset(5, 0).Address
MsgBox ActiveCell.Resize(6, 1).Address

--
HTH...

Jim Thomlinson


"Caeres" wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default How do I use the .Cells property to refer to ActiveCell?

Here's the end goal. I'm trying to sort a range from the active cell to N3.
Here's the code I've got right now:

ActiveCell.Select
With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
.SortFields.Clear
.SortFields.Add Key:=Range(Cells(ActiveCell.Row, ActiveCell.Column),
Cells(3, 14)), _
SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
.SetRange Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(3,
14))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

and I get an error message:
"Run-time error '1004': The sort reference is not valid. Make sure that
it's within the data you want to sort, and the first Sort By box isn't the
same or blank."

with the ".SetRange" line highlighted in the debugger. Any ideas? Thanks
for the initial help, that was what I was looking for. Just turns out it
wasn't my only problem.

"Jim Thomlinson" wrote:

Your request does not really make a lot of sense??? The active cell is a
single cell on the active sheet. Are you trying to define a range based off
of the active cell???

MsgBox Cells(ActiveCell.Row, ActiveCell.Column).Address
MsgBox Cells(ActiveCell.Row + 5, ActiveCell.Column).Address
MsgBox ActiveCell.Offset(5, 0).Address
MsgBox ActiveCell.Resize(6, 1).Address

--
HTH...

Jim Thomlinson


"Caeres" wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?

  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 342
Default How do I use the .Cells property to refer to ActiveCell?

Once you have identified the range you need to decide what column(s) you want
to sort on. Do you know?

Tom

"Caeres" wrote:

Here's the end goal. I'm trying to sort a range from the active cell to N3.
Here's the code I've got right now:

ActiveCell.Select
With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
.SortFields.Clear
.SortFields.Add Key:=Range(Cells(ActiveCell.Row, ActiveCell.Column),
Cells(3, 14)), _
SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
.SetRange Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(3,
14))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

and I get an error message:
"Run-time error '1004': The sort reference is not valid. Make sure that
it's within the data you want to sort, and the first Sort By box isn't the
same or blank."

with the ".SetRange" line highlighted in the debugger. Any ideas? Thanks
for the initial help, that was what I was looking for. Just turns out it
wasn't my only problem.

"Jim Thomlinson" wrote:

Your request does not really make a lot of sense??? The active cell is a
single cell on the active sheet. Are you trying to define a range based off
of the active cell???

MsgBox Cells(ActiveCell.Row, ActiveCell.Column).Address
MsgBox Cells(ActiveCell.Row + 5, ActiveCell.Column).Address
MsgBox ActiveCell.Offset(5, 0).Address
MsgBox ActiveCell.Resize(6, 1).Address

--
HTH...

Jim Thomlinson


"Caeres" wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?

  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default How do I use the .Cells property to refer to ActiveCell?

Yes, I want to sort based on column A.

"TomPl" wrote:

Once you have identified the range you need to decide what column(s) you want
to sort on. Do you know?

Tom

"Caeres" wrote:

Here's the end goal. I'm trying to sort a range from the active cell to N3.
Here's the code I've got right now:

ActiveCell.Select
With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
.SortFields.Clear
.SortFields.Add Key:=Range(Cells(ActiveCell.Row, ActiveCell.Column),
Cells(3, 14)), _
SortOn:=xlSortOnValues, Order:=xlAscending,
DataOption:=xlSortNormal
.SetRange Range(Cells(ActiveCell.Row, ActiveCell.Column), Cells(3,
14))
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

and I get an error message:
"Run-time error '1004': The sort reference is not valid. Make sure that
it's within the data you want to sort, and the first Sort By box isn't the
same or blank."

with the ".SetRange" line highlighted in the debugger. Any ideas? Thanks
for the initial help, that was what I was looking for. Just turns out it
wasn't my only problem.

"Jim Thomlinson" wrote:

Your request does not really make a lot of sense??? The active cell is a
single cell on the active sheet. Are you trying to define a range based off
of the active cell???

MsgBox Cells(ActiveCell.Row, ActiveCell.Column).Address
MsgBox Cells(ActiveCell.Row + 5, ActiveCell.Column).Address
MsgBox ActiveCell.Offset(5, 0).Address
MsgBox ActiveCell.Resize(6, 1).Address

--
HTH...

Jim Thomlinson


"Caeres" wrote:

I need to refer to the active cell using the Cells property (eg
Range.Cells(...)). How do I do this?

  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 342
Default How do I use the .Cells property to refer to ActiveCell?

I'm not sure the point to all of this, but the following should do what you
have described. This will sort the data in columns A thru N based on the
value in column A. Only rows 4 thru the row of the active cell will be
sorted.

Sub SortSelection()

Dim rngCell As String

rngCell = ActiveCell.Row

ActiveSheet.Range("A3:N" & rngCell).Sort Key1:=Range("a4"),
Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveSheet.Range("A" & rngCell).Select

End Sub

Hope'n this works.

Tom
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15
Default How do I use the .Cells property to refer to ActiveCell?

Had a few problems with your code, but you answered my question. I was
inputting the key value wrong. Thanks for the help.

"TomPl" wrote:

I'm not sure the point to all of this, but the following should do what you
have described. This will sort the data in columns A thru N based on the
value in column A. Only rows 4 thru the row of the active cell will be
sorted.

Sub SortSelection()

Dim rngCell As String

rngCell = ActiveCell.Row

ActiveSheet.Range("A3:N" & rngCell).Sort Key1:=Range("a4"),
Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveSheet.Range("A" & rngCell).Select

End Sub

Hope'n this works.

Tom

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
how to find cells that refer to data in other cells in excel Aman Excel Discussion (Misc queries) 8 December 2nd 07 10:02 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
Using cells to refer to worksheets Rup1776 Excel Worksheet Functions 1 September 27th 06 09:36 AM
Why do some Excel cells refer to e-mail? Fred in Keswick Excel Worksheet Functions 1 February 28th 06 10:09 PM
To get a lot of charts that refer to different cells Anderson Lee Charts and Charting in Excel 1 December 28th 04 02:35 PM


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