Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default simple vb question

How do I poll the number of the selected row on a non-selected
worksheet?

My crude attempt looks like this:

=Worksheets("caseload").Selection.Row

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default simple vb question

Bounce back and forth:

For example to get the row of the acitvecell on Sheet1 from any sheet:

Sub whichRow()
Set cSheet = ActiveSheet
Sheets("Sheet1").Activate
n = ActiveCell.Row
cSheet.Activate
MsgBox (n)
End Sub


--
Gary''s Student - gsnu200805


" wrote:

How do I poll the number of the selected row on a non-selected
worksheet?

My crude attempt looks like this:

=Worksheets("caseload").Selection.Row


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default simple vb question

Option Explicit
Sub testme()

Dim ActWks As Worksheet
Dim myRow As Long

Application.ScreenUpdating = False
Set ActWks = ActiveSheet
With Worksheets("CaseLoad")
.Select
myRow = Selection.Row
End With
ActWks.Select
Application.ScreenUpdating = True

MsgBox myRow

End Sub

" wrote:

How do I poll the number of the selected row on a non-selected
worksheet?

My crude attempt looks like this:

=Worksheets("caseload").Selection.Row


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default simple vb question

The codes posted are exactly what I asked for. Thanks to both of
you..

I still have a problem in that the code is activated by a
Worksheet_Activate sub. The toggling between worksheets causes the
code to loop endlessly. I'm not sure how to set up a flag that will
only allow a single activation of the subroutine.

..Private Sub Worksheet_Activate()
Dim ActWks As Worksheet
Dim myRow As Long
Application.ScreenUpdating = False
Set ActWks = ActiveSheet
With Worksheets("CaseLoad")
.Select
selectedrow = Selection.Row
End With
updateflag = 1
ActWks.Select
Application.ScreenUpdating = True

Cells(4, 112).Value = Worksheets("caseload").Cells(selectedrow,
1).Value
End Sub

sorry to complicate a simple question.
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default simple vb question

The problem can be avoided by using the Deactivate Event rather than the
Activate Event.

Let's say that for each worksheet we have a Deactivate macro that just
records the address of the activecell in a public, static, string variable.

That way, any time a worksheet and been activated and then deactivated, any
other sheet will have direct access to the other sheet's most recent active
cell.

Thus you can avoid the "bouncing" behavior in my previous post.
--
Gary''s Student - gsnu2007k


" wrote:

The codes posted are exactly what I asked for. Thanks to both of
you..

I still have a problem in that the code is activated by a
Worksheet_Activate sub. The toggling between worksheets causes the
code to loop endlessly. I'm not sure how to set up a flag that will
only allow a single activation of the subroutine.

..Private Sub Worksheet_Activate()
Dim ActWks As Worksheet
Dim myRow As Long
Application.ScreenUpdating = False
Set ActWks = ActiveSheet
With Worksheets("CaseLoad")
.Select
selectedrow = Selection.Row
End With
updateflag = 1
ActWks.Select
Application.ScreenUpdating = True

Cells(4, 112).Value = Worksheets("caseload").Cells(selectedrow,
1).Value
End Sub

sorry to complicate a simple question.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default simple vb question

On Sep 15, 11:25*am, Gary''s Student
wrote:
The problem can be avoided by using the Deactivate Event rather than the
Activate Event.

Let's say that for each worksheet we have a Deactivate macro that just
records the address of the activecell in a public, static, string variable.

That way, any time a worksheet and been activated and then deactivated, any
other sheet will have direct access to the other sheet's most recent active
cell.

Thus you can avoid the "bouncing" behavior in my previous post.
--
Gary''s Student - gsnu2007k


This is what I had before coming to the Newsgroup. The problem was
that the subroutine that kept track of the row was triggered every
time I moved to a new cell -- it made it cumbersome to navigate
because of the lag it created.
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default simple vb question

My mistake. You are correct, Deactivate does not run soon enough. You would
need the selection_change event.
--
Gary''s Student - gsnu200805


" wrote:

On Sep 15, 11:25 am, Gary''s Student
wrote:
The problem can be avoided by using the Deactivate Event rather than the
Activate Event.

Let's say that for each worksheet we have a Deactivate macro that just
records the address of the activecell in a public, static, string variable.

That way, any time a worksheet and been activated and then deactivated, any
other sheet will have direct access to the other sheet's most recent active
cell.

Thus you can avoid the "bouncing" behavior in my previous post.
--
Gary''s Student - gsnu2007k


This is what I had before coming to the Newsgroup. The problem was
that the subroutine that kept track of the row was triggered every
time I moved to a new cell -- it made it cumbersome to navigate
because of the lag it created.

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
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple Question - Please Help! Mark31 Charts and Charting in Excel 0 November 26th 07 06:38 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
Simple Question Rookie[_2_] Excel Programming 1 April 26th 04 07:03 PM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM


All times are GMT +1. The time now is 11:36 PM.

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"