Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Selective selecting of multiple tabs

Hi,

I've got a workbook with one tab for data entry and the other tab for
data presentation (with imbedded formulas for %differences from
controls and such). Initially, both sheets are identical, but I
sometimes need to insert rows and columns. Rather than doing this
twice, I just select both tabs. The problem is that I (and others)
oftentimes forget to have both tabs selected during modification or
data entry, and we end up having to waste time fixing things. So, I
drafted a quick macro for the Worksheet_SelectionChange event that I
thought would work well, but I've got a snag. It reads the address of
the active cell, then checks the same cell in the 2nd sheet for the
formula. IF the formula starts a certain way (with =IF(ISERRO), then
I want the macro to end. If it doesn't start with that, then I want
the macro to force the selection of the second tab. But, it's failing
when it tries to check the same cell on the 2nd sheet. The macro
seems to work if I try it outside of the event routine, but when I put
it in the Worksheet, it fails. Can anyone give me advice on how to
fix and/or improve this please? Thanks.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
myActiveCell = ActiveCell.Address
Sheets("CTD").Activate
Range(myActiveCell).Activate ' IT'S FAILING RIGHT HERE. WHY?
myFormula = ActiveCell.FormulaR1C1
myStartFormula = Mid(myFormula, 1, 11)
If myStartFormula = "=IF(ISERROR" Then
Sheets("Data Entry").Select
GoTo Line1
Else

Sheets(Array("Data Entry", "CTD")).Select

End If

Line1:
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Selective selecting of multiple tabs

on 4/15/2011, Phrank supposed :
Hi,

I've got a workbook with one tab for data entry and the other tab for
data presentation (with imbedded formulas for %differences from
controls and such). Initially, both sheets are identical, but I
sometimes need to insert rows and columns. Rather than doing this
twice, I just select both tabs. The problem is that I (and others)
oftentimes forget to have both tabs selected during modification or
data entry, and we end up having to waste time fixing things. So, I
drafted a quick macro for the Worksheet_SelectionChange event that I
thought would work well, but I've got a snag. It reads the address of
the active cell, then checks the same cell in the 2nd sheet for the
formula. IF the formula starts a certain way (with =IF(ISERRO), then
I want the macro to end. If it doesn't start with that, then I want
the macro to force the selection of the second tab. But, it's failing
when it tries to check the same cell on the 2nd sheet. The macro
seems to work if I try it outside of the event routine, but when I put
it in the Worksheet, it fails. Can anyone give me advice on how to
fix and/or improve this please? Thanks.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
myActiveCell = ActiveCell.Address
Sheets("CTD").Activate
Range(myActiveCell).Activate ' IT'S FAILING RIGHT HERE. WHY?
myFormula = ActiveCell.FormulaR1C1
myStartFormula = Mid(myFormula, 1, 11)
If myStartFormula = "=IF(ISERROR" Then
Sheets("Data Entry").Select
GoTo Line1
Else

Sheets(Array("Data Entry", "CTD")).Select

End If

Line1:
End Sub


Try using the Worksheet_Change event instead. Though I feel you might
be better off putting code behind a custom menuitem so people can just
insert rows/columns based on a position of the active cell on either
sheet. Otherwise, you'll have to put code behind each sheet.

You could add custom menuitems to the right-click popup menu to make
the process more convenient. I'd use one menuitem for rows, another for
columns. If you're interested in this approach post back and say so and
I'll try to help you with it.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Selective selecting of multiple tabs

I tried the Worksheet_Change event, and that's no good because it
initiated the macro every time I even selected a cell. There are only
two sheets in each workbook. ...well, there's actually a 3rd worksheet
(Notes) with notes as to what to do under certain circumstances. This
3rd sheet is helpful, too, with my code, because if for some reason
someone wants to access the CTD sheet, all they need to do is click on
the Notes tab to deselect the other two tabs, then the can select the
CTD tab alone. That part works well. I just need it to be able to
look at the analagous cell in the 2nd tab and press on with the macro.
For some reason, it's working when tested outside of the
Worksheet_SelectionChange event, but not working inside the event.
Thanks.

Frank


On Fri, 15 Apr 2011 19:52:50 -0400, GS wrote:

on 4/15/2011, Phrank supposed :
Hi,

I've got a workbook with one tab for data entry and the other tab for
data presentation (with imbedded formulas for %differences from
controls and such). Initially, both sheets are identical, but I
sometimes need to insert rows and columns. Rather than doing this
twice, I just select both tabs. The problem is that I (and others)
oftentimes forget to have both tabs selected during modification or
data entry, and we end up having to waste time fixing things. So, I
drafted a quick macro for the Worksheet_SelectionChange event that I
thought would work well, but I've got a snag. It reads the address of
the active cell, then checks the same cell in the 2nd sheet for the
formula. IF the formula starts a certain way (with =IF(ISERRO), then
I want the macro to end. If it doesn't start with that, then I want
the macro to force the selection of the second tab. But, it's failing
when it tries to check the same cell on the 2nd sheet. The macro
seems to work if I try it outside of the event routine, but when I put
it in the Worksheet, it fails. Can anyone give me advice on how to
fix and/or improve this please? Thanks.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
myActiveCell = ActiveCell.Address
Sheets("CTD").Activate
Range(myActiveCell).Activate ' IT'S FAILING RIGHT HERE. WHY?
myFormula = ActiveCell.FormulaR1C1
myStartFormula = Mid(myFormula, 1, 11)
If myStartFormula = "=IF(ISERROR" Then
Sheets("Data Entry").Select
GoTo Line1
Else

Sheets(Array("Data Entry", "CTD")).Select

End If

Line1:
End Sub


Try using the Worksheet_Change event instead. Though I feel you might
be better off putting code behind a custom menuitem so people can just
insert rows/columns based on a position of the active cell on either
sheet. Otherwise, you'll have to put code behind each sheet.

You could add custom menuitems to the right-click popup menu to make
the process more convenient. I'd use one menuitem for rows, another for
columns. If you're interested in this approach post back and say so and
I'll try to help you with it.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Selective selecting of multiple tabs

Phrank wrote :
I tried the Worksheet_Change event, and that's no good because it
initiated the macro every time I even selected a cell. There are only
two sheets in each workbook. ...well, there's actually a 3rd worksheet
(Notes) with notes as to what to do under certain circumstances. This
3rd sheet is helpful, too, with my code, because if for some reason
someone wants to access the CTD sheet, all they need to do is click on
the Notes tab to deselect the other two tabs, then the can select the
CTD tab alone. That part works well. I just need it to be able to
look at the analagous cell in the 2nd tab and press on with the macro.
For some reason, it's working when tested outside of the
Worksheet_SelectionChange event, but not working inside the event.
Thanks.

Frank


Both events fire whenever cells are selected. I really don't think this
is where you want to put this code. I reiterate the idea of putting it
in a standard module and running it from a menuitem on the right-click
popup menu. This, then, would work since you claim it works outside
either of those events.

So.., do you want help to do this OR do you want to fiddle with it a
bit more?

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Selective selecting of multiple tabs

It is good practice to use Option Explicit and declare all variables.
In worksheet event code "Target" is the active cell.
Qualify all ranges with the parent sheet (and the workbook if there is more than one).
The following code is untested but should be close to what you want...
'---
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myActiveCell As String
Dim myFormula As String

myActiveCell = Target(1).Address(False, False)
myFormula = Sheets("CTD").Range(myActiveCell).FormulaR1C1
If InStr(1, myFormula, "=IF(ISERROR", vbTextCompare) Then
Sheets("Data Entry").Select
Else
Sheets(Array("Data Entry", "CTD")).Select
End If
End Sub
'---
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(Determine Colors (excel add-in) - in the free folder)




"Phrank"
wrote in message
...
I tried the Worksheet_Change event, and that's no good because it
initiated the macro every time I even selected a cell. There are only
two sheets in each workbook. ...well, there's actually a 3rd worksheet
(Notes) with notes as to what to do under certain circumstances. This
3rd sheet is helpful, too, with my code, because if for some reason
someone wants to access the CTD sheet, all they need to do is click on
the Notes tab to deselect the other two tabs, then the can select the
CTD tab alone. That part works well. I just need it to be able to
look at the analagous cell in the 2nd tab and press on with the macro.
For some reason, it's working when tested outside of the
Worksheet_SelectionChange event, but not working inside the event.
Thanks.
Frank





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Selective selecting of multiple tabs

That works great!! Thank you so much!

For Garry, the reason I want it in an event is because I and others
periodically forget to select both tabs, which leads to extra work.
I'm just as likely to forget to right click and run this from a menu
item as I am to actually select both tabs. ...unless you were
thinking of something else. The automation of the procedure is what
I'm after, and Jim's fixing of my code seems to do the trick.

Thanks!

Frank

On Fri, 15 Apr 2011 20:05:33 -0700, "Jim Cone"
wrote:

It is good practice to use Option Explicit and declare all variables.
In worksheet event code "Target" is the active cell.
Qualify all ranges with the parent sheet (and the workbook if there is more than one).
The following code is untested but should be close to what you want...
'---
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myActiveCell As String
Dim myFormula As String

myActiveCell = Target(1).Address(False, False)
myFormula = Sheets("CTD").Range(myActiveCell).FormulaR1C1
If InStr(1, myFormula, "=IF(ISERROR", vbTextCompare) Then
Sheets("Data Entry").Select
Else
Sheets(Array("Data Entry", "CTD")).Select
End If
End Sub
'---
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(Determine Colors (excel add-in) - in the free folder)




"Phrank"
wrote in message
.. .
I tried the Worksheet_Change event, and that's no good because it
initiated the macro every time I even selected a cell. There are only
two sheets in each workbook. ...well, there's actually a 3rd worksheet
(Notes) with notes as to what to do under certain circumstances. This
3rd sheet is helpful, too, with my code, because if for some reason
someone wants to access the CTD sheet, all they need to do is click on
the Notes tab to deselect the other two tabs, then the can select the
CTD tab alone. That part works well. I just need it to be able to
look at the analagous cell in the 2nd tab and press on with the macro.
For some reason, it's working when tested outside of the
Worksheet_SelectionChange event, but not working inside the event.
Thanks.
Frank


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Selective selecting of multiple tabs

Phrank expressed precisely :
For Garry, the reason I want it in an event is because I and others
periodically forget to select both tabs, which leads to extra work.
I'm just as likely to forget to right click and run this from a menu
item as I am to actually select both tabs. ...unless you were
thinking of something else. The automation of the procedure is what
I'm after, and Jim's fixing of my code seems to do the trick.

Thanks!

Frank


I'm glad Jim was able to help you. My thinking was that SINCE YOU MUST
USE A MENU FROM SOMEWHERE (menubar or cell popup) to insert rows/cols
then why not 'train' yourself and your users to use your own custom
menus for automated tasks.

Using event code constantly adds to performance overhead; using a
menuitem only adds when needed!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 153
Default Selective selecting of multiple tabs

Hi again,

Is there a way to tweak this macro so that the formatting in the cell
on the CTD sheet matches that of the same cell on the Data Entry
sheet? When data get entered, sometimes it needs to be center
justified and sometimes it needs to be right justified, and
significant figures change too. Thanks.

Frank

On Fri, 15 Apr 2011 20:05:33 -0700, "Jim Cone"
wrote:

It is good practice to use Option Explicit and declare all variables.
In worksheet event code "Target" is the active cell.
Qualify all ranges with the parent sheet (and the workbook if there is more than one).
The following code is untested but should be close to what you want...
'---
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim myActiveCell As String
Dim myFormula As String

myActiveCell = Target(1).Address(False, False)
myFormula = Sheets("CTD").Range(myActiveCell).FormulaR1C1
If InStr(1, myFormula, "=IF(ISERROR", vbTextCompare) Then
Sheets("Data Entry").Select
Else
Sheets(Array("Data Entry", "CTD")).Select
End If
End Sub
'---
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(Determine Colors (excel add-in) - in the free folder)




"Phrank"
wrote in message
.. .
I tried the Worksheet_Change event, and that's no good because it
initiated the macro every time I even selected a cell. There are only
two sheets in each workbook. ...well, there's actually a 3rd worksheet
(Notes) with notes as to what to do under certain circumstances. This
3rd sheet is helpful, too, with my code, because if for some reason
someone wants to access the CTD sheet, all they need to do is click on
the Notes tab to deselect the other two tabs, then the can select the
CTD tab alone. That part works well. I just need it to be able to
look at the analagous cell in the 2nd tab and press on with the macro.
For some reason, it's working when tested outside of the
Worksheet_SelectionChange event, but not working inside the event.
Thanks.
Frank


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
Selecting multiple tabs in VB Shawn777 Excel Programming 12 December 19th 07 06:23 PM
Selecting Page Tabs Millington Excel Discussion (Misc queries) 2 August 29th 07 08:24 PM
Merging multiple worksheets (selective cells) Soultek Excel Discussion (Misc queries) 1 February 22nd 07 06:54 PM
selecting spreadsheet using tabs? Hoyos Excel Discussion (Misc queries) 0 December 1st 06 10:19 PM
selecting multiple sheet tabs and open another workbook Bannor Excel Discussion (Misc queries) 5 November 25th 05 02:38 AM


All times are GMT +1. The time now is 10:14 AM.

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"