Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default getting the selected range and active cell of a non active worksheetsheet

Can one access the active cell of a non active sheet (without activating it
first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default getting the selected range and active cell of a non active worksheetsheet

There is no active cell if the sheet is not active.


"GerryGerry" wrote in message
...
Can one access the active cell of a non active sheet (without activating
it first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default getting the selected range and active cell of a non active workshe

Hi,

If a sheet is not active, no cells have focus, none are active, none are
selected. You cannot use those properties on an inactive sheet.

If you want the address of the cell that would be active if the sheet was
selected then you can do this

Application.ScreenUpdating = False
Sheets("Sheet2").Select
Where = Selection.Address
Sheets("Sheet1").Select
MsgBox "The selected cell on Sheet2 is " & Where
Application.ScreenUpdating = True

With screenupdating being false you will not see sheet 2 being fleetingly
activated.

Mike

"GerryGerry" wrote:

Can one access the active cell of a non active sheet (without activating it
first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default getting the selected range and active cell of a non active worksheetsheet

You can access a cell or a range on an inactive (not hidden) sheet by
specific value. Assume Sheet1 is the active sheet:

Sheets("Sheet2").Range("B4") = ActiveSheet.Range("A1").Value

would put the value of A1 in the active sheet into cell B4 of sheet2 without
activating sheet2. You can do the same thing in reverse:

ActiveSheet.Range("A1") = Sheets("Sheet2").Range("B4").Value


"GerryGerry" wrote in message
...
Can one access the active cell of a non active sheet (without activating
it first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default getting the selected range and active cell of a non active workshe

Hi,

Thank you for this. You have understood exactly what I wanted although I did
use the wrong terminology. I was wondering whether this was achievable
without activating the sheet (even with screenupdating turned off). It seems
a little surprising to me that this info is not accessible directly somehow
through excels object model.

It's not just that the code is cumbersome, it's the fact that I can't loose
the focus of the current cell while obtaining values from the other
worksheets in my intended application.

Thanks to all
Gerry

"Mike H" wrote in message
...
Hi,

If a sheet is not active, no cells have focus, none are active, none are
selected. You cannot use those properties on an inactive sheet.

If you want the address of the cell that would be active if the sheet was
selected then you can do this

Application.ScreenUpdating = False
Sheets("Sheet2").Select
Where = Selection.Address
Sheets("Sheet1").Select
MsgBox "The selected cell on Sheet2 is " & Where
Application.ScreenUpdating = True

With screenupdating being false you will not see sheet 2 being fleetingly
activated.

Mike

"GerryGerry" wrote:

Can one access the active cell of a non active sheet (without activating
it
first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default getting the selected range and active cell of a non active wor

Hi,

I'm struggling to understand what value it brings knowing this about an
inactive sheet. If you want a value from a sheet you can get it without any
sheet\range selection and the same goes for writing a value.

Mike

"GerryGerry" wrote:

Hi,

Thank you for this. You have understood exactly what I wanted although I did
use the wrong terminology. I was wondering whether this was achievable
without activating the sheet (even with screenupdating turned off). It seems
a little surprising to me that this info is not accessible directly somehow
through excels object model.

It's not just that the code is cumbersome, it's the fact that I can't loose
the focus of the current cell while obtaining values from the other
worksheets in my intended application.

Thanks to all
Gerry

"Mike H" wrote in message
...
Hi,

If a sheet is not active, no cells have focus, none are active, none are
selected. You cannot use those properties on an inactive sheet.

If you want the address of the cell that would be active if the sheet was
selected then you can do this

Application.ScreenUpdating = False
Sheets("Sheet2").Select
Where = Selection.Address
Sheets("Sheet1").Select
MsgBox "The selected cell on Sheet2 is " & Where
Application.ScreenUpdating = True

With screenupdating being false you will not see sheet 2 being fleetingly
activated.

Mike

"GerryGerry" wrote:

Can one access the active cell of a non active sheet (without activating
it
first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default getting the selected range and active cell of a non active workshe

Why would changing sheets to find the activecell, then changing back to the
original worksheet cause a problem?

If you have events that do things, turn them off.

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim StartingWks As Worksheet

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set StartingWks = ActiveSheet

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = ActiveSheet.Name Then
'skip it
Else
wks.Activate
MsgBox ActiveCell.Address(external:=True)
End If
Next wks

StartingWks.Activate

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

End Sub

GerryGerry wrote:

Hi,

Thank you for this. You have understood exactly what I wanted although I did
use the wrong terminology. I was wondering whether this was achievable
without activating the sheet (even with screenupdating turned off). It seems
a little surprising to me that this info is not accessible directly somehow
through excels object model.

It's not just that the code is cumbersome, it's the fact that I can't loose
the focus of the current cell while obtaining values from the other
worksheets in my intended application.

Thanks to all
Gerry

"Mike H" wrote in message
...
Hi,

If a sheet is not active, no cells have focus, none are active, none are
selected. You cannot use those properties on an inactive sheet.

If you want the address of the cell that would be active if the sheet was
selected then you can do this

Application.ScreenUpdating = False
Sheets("Sheet2").Select
Where = Selection.Address
Sheets("Sheet1").Select
MsgBox "The selected cell on Sheet2 is " & Where
Application.ScreenUpdating = True

With screenupdating being false you will not see sheet 2 being fleetingly
activated.

Mike

"GerryGerry" wrote:

Can one access the active cell of a non active sheet (without activating
it
first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)




--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default getting the selected range and active cell of a non active workshe

Thank you for this. I'll try it tommorow and let everyone know how it went.

"Dave Peterson" wrote in message
...
Why would changing sheets to find the activecell, then changing back to
the
original worksheet cause a problem?

If you have events that do things, turn them off.

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim StartingWks As Worksheet

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

Set StartingWks = ActiveSheet

For Each wks In ActiveWorkbook.Worksheets
If wks.Name = ActiveSheet.Name Then
'skip it
Else
wks.Activate
MsgBox ActiveCell.Address(external:=True)
End If
Next wks

StartingWks.Activate

With Application
.ScreenUpdating = False
.EnableEvents = False
End With

End Sub

GerryGerry wrote:

Hi,

Thank you for this. You have understood exactly what I wanted although I
did
use the wrong terminology. I was wondering whether this was achievable
without activating the sheet (even with screenupdating turned off). It
seems
a little surprising to me that this info is not accessible directly
somehow
through excels object model.

It's not just that the code is cumbersome, it's the fact that I can't
loose
the focus of the current cell while obtaining values from the other
worksheets in my intended application.

Thanks to all
Gerry

"Mike H" wrote in message
...
Hi,

If a sheet is not active, no cells have focus, none are active, none
are
selected. You cannot use those properties on an inactive sheet.

If you want the address of the cell that would be active if the sheet
was
selected then you can do this

Application.ScreenUpdating = False
Sheets("Sheet2").Select
Where = Selection.Address
Sheets("Sheet1").Select
MsgBox "The selected cell on Sheet2 is " & Where
Application.ScreenUpdating = True

With screenupdating being false you will not see sheet 2 being
fleetingly
activated.

Mike

"GerryGerry" wrote:

Can one access the active cell of a non active sheet (without
activating
it
first) in VBA as well as the selected range?

any help much appreciated as always
(i'm using Excel 2003)




--

Dave Peterson



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
Row select mode to highlight active row of active cell Bart Fay[_2_] Excel Discussion (Misc queries) 0 May 11th 10 09:34 PM
run macro although blinking cursor is active in an active cell bartman1980 Excel Programming 1 December 20th 07 11:29 AM
selecting row from active cell selected mikla[_3_] Excel Programming 1 August 7th 06 06:08 PM
Moving active window to selected range GoFigure[_11_] Excel Programming 2 December 6th 05 05:08 PM
How to obtain the number of Column and Row from selected (active)cell? And1 Excel Programming 3 December 5th 05 09:30 PM


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