Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 419
Default Making changes on "grouped" sheets via code

Hello all,

If I run the following code on "grouped" sheets (more than one sheet
selected), the selected cells on ONLY the active sheet will be changed...all
other selected sheets will remain unchanged. If I were to change these
cells manually, all selected sheets will be changed.



Sub ReplaceReferences()
Dim prngCell As Range
Dim pbytNamedRange As Byte
Dim pbytIndex As Byte

pbytNamedRange = 1
pbytIndex = 1

For Each prngCell In Selection
prngCell.Formula = "'=" & Range("rngStartBals." &
pbytNamedRange).Cells(pbytIndex).Address(True, True, xlA1, True)
' ActiveWindow.SelectedSheets.prngCell.Formula = "'=" &
Range("rngStartBals." & pbytNamedRange).Cells(pbytIndex).Address(True, True,
xlA1, True)
pbytIndex = pbytIndex + 1
Next prngCell
End Sub



Is there some quick, simple way to get this to affect all selected sheets or
will I have to loop through all selected sheets and then loop through cells?
If looping through sheets then cells, no need to post modified code. I'm
pretty sure I can figure that out.

As you can tell by the commented-out line of code, I tried to qualify my
range variable with "ActiveWindow.SelectedSheets." and no workie. Hoping
for something simple like that, but will settle for looping through sheets
if necessary.

Thanks for any help anyone can provide,

Conan Kelly


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Making changes on "grouped" sheets via code

No you will not be able to group and update via a macro. You are correct in
your assessment to loop through the sheets and update them individually...

--
HTH...

Jim Thomlinson


"Conan Kelly" wrote:

Hello all,

If I run the following code on "grouped" sheets (more than one sheet
selected), the selected cells on ONLY the active sheet will be changed...all
other selected sheets will remain unchanged. If I were to change these
cells manually, all selected sheets will be changed.



Sub ReplaceReferences()
Dim prngCell As Range
Dim pbytNamedRange As Byte
Dim pbytIndex As Byte

pbytNamedRange = 1
pbytIndex = 1

For Each prngCell In Selection
prngCell.Formula = "'=" & Range("rngStartBals." &
pbytNamedRange).Cells(pbytIndex).Address(True, True, xlA1, True)
' ActiveWindow.SelectedSheets.prngCell.Formula = "'=" &
Range("rngStartBals." & pbytNamedRange).Cells(pbytIndex).Address(True, True,
xlA1, True)
pbytIndex = pbytIndex + 1
Next prngCell
End Sub



Is there some quick, simple way to get this to affect all selected sheets or
will I have to loop through all selected sheets and then loop through cells?
If looping through sheets then cells, no need to post modified code. I'm
pretty sure I can figure that out.

As you can tell by the commented-out line of code, I tried to qualify my
range variable with "ActiveWindow.SelectedSheets." and no workie. Hoping
for something simple like that, but will settle for looping through sheets
if necessary.

Thanks for any help anyone can provide,

Conan Kelly



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 419
Default Making changes on "grouped" sheets via code

Jim,

Thanks for the feedback.

Not quite the answer I was hoping for, but looping through sheets is not
that much work.

Thanks again for all of your help,

Conan




"Jim Thomlinson" wrote in message
...
No you will not be able to group and update via a macro. You are correct
in
your assessment to loop through the sheets and update them individually...

--
HTH...

Jim Thomlinson


"Conan Kelly" wrote:

Hello all,

If I run the following code on "grouped" sheets (more than one sheet
selected), the selected cells on ONLY the active sheet will be
changed...all
other selected sheets will remain unchanged. If I were to change these
cells manually, all selected sheets will be changed.



Sub ReplaceReferences()
Dim prngCell As Range
Dim pbytNamedRange As Byte
Dim pbytIndex As Byte

pbytNamedRange = 1
pbytIndex = 1

For Each prngCell In Selection
prngCell.Formula = "'=" & Range("rngStartBals." &
pbytNamedRange).Cells(pbytIndex).Address(True, True, xlA1, True)
' ActiveWindow.SelectedSheets.prngCell.Formula = "'=" &
Range("rngStartBals." & pbytNamedRange).Cells(pbytIndex).Address(True,
True,
xlA1, True)
pbytIndex = pbytIndex + 1
Next prngCell
End Sub



Is there some quick, simple way to get this to affect all selected sheets
or
will I have to loop through all selected sheets and then loop through
cells?
If looping through sheets then cells, no need to post modified code. I'm
pretty sure I can figure that out.

As you can tell by the commented-out line of code, I tried to qualify my
range variable with "ActiveWindow.SelectedSheets." and no workie. Hoping
for something simple like that, but will settle for looping through
sheets
if necessary.

Thanks for any help anyone can provide,

Conan Kelly





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 419
Default Making changes on "grouped" sheets via code

Jim (or others),

Kind of a follow-up question:

"Selection" is selected cell(s)/range(s) (or other selected objects...but
talking about just cells/ranges right now) on the active sheet *ONLY*,
correct?

Just out of curiosity, is it possible to access the "selected" cells on the
other sheets in the group without making those sheets active?

For example:



Sub testing()
Dim prngCell As Range
Dim pshtSheet As Worksheet

pbytNamedRange = 1

For Each pshtSheet In ActiveWindow.SelectedSheets
' pshtSheet.Activate
For Each prngCell In Selection
Debug.Print pshtSheet.prngCell.Address(False, False, xlA1, True)
Next prngCell
Next pshtSheet
End Sub


....won't work (pshtSheet.Activate is commented out) becasue prngCell is not
a member of pshtSheet. Worksheet objects don't have a "SelectedCells"
property, even though I would consider worksheets to technically have
selected cells (XL/VBA might not consider that).

Is the only way to access those cells and alter them to make their sheet
active?

Thanks again for all of your help,

Conan





"Jim Thomlinson" wrote in message
...
No you will not be able to group and update via a macro. You are correct
in
your assessment to loop through the sheets and update them individually...

--
HTH...

Jim Thomlinson


"Conan Kelly" wrote:

Hello all,

If I run the following code on "grouped" sheets (more than one sheet
selected), the selected cells on ONLY the active sheet will be
changed...all
other selected sheets will remain unchanged. If I were to change these
cells manually, all selected sheets will be changed.



Sub ReplaceReferences()
Dim prngCell As Range
Dim pbytNamedRange As Byte
Dim pbytIndex As Byte

pbytNamedRange = 1
pbytIndex = 1

For Each prngCell In Selection
prngCell.Formula = "'=" & Range("rngStartBals." &
pbytNamedRange).Cells(pbytIndex).Address(True, True, xlA1, True)
' ActiveWindow.SelectedSheets.prngCell.Formula = "'=" &
Range("rngStartBals." & pbytNamedRange).Cells(pbytIndex).Address(True,
True,
xlA1, True)
pbytIndex = pbytIndex + 1
Next prngCell
End Sub



Is there some quick, simple way to get this to affect all selected sheets
or
will I have to loop through all selected sheets and then loop through
cells?
If looping through sheets then cells, no need to post modified code. I'm
pretty sure I can figure that out.

As you can tell by the commented-out line of code, I tried to qualify my
range variable with "ActiveWindow.SelectedSheets." and no workie. Hoping
for something simple like that, but will settle for looping through
sheets
if necessary.

Thanks for any help anyone can provide,

Conan Kelly





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Making changes on "grouped" sheets via code

You cannot do what you want with "select". However, you do not have to
activate other sheets to execute commands on them. Here are some examples:

Sheets("Sheet1") is the active sheet.
With.Sheets(2).Range("B5:H10").Font 'Changes font setting on
.Name = "Arial" 'Sheet 2 while Sheet 1
.Size = 12 'is still active and
visible.
.Bold = True
End With

This one will change text to Upper Case on sheet 3
without activating that sheet.

Dim c As Range
For Each c In Worksheets(3).Range("A1:A20:")
If Not c Is Nothing Then
If c.Value < UCase(c.Value) Then
c.Value = UCase(c.Value)
End If
End If
Next

It just requires using routing instructions like the sheet and range
with each command, rather than activating and selecting. The
activating and selecting mimics a manual operation, whereas the
qualification method simulates the manual operation in results only.

"Conan Kelly" wrote:

Jim (or others),

Kind of a follow-up question:

"Selection" is selected cell(s)/range(s) (or other selected objects...but
talking about just cells/ranges right now) on the active sheet *ONLY*,
correct?

Just out of curiosity, is it possible to access the "selected" cells on the
other sheets in the group without making those sheets active?

For example:



Sub testing()
Dim prngCell As Range
Dim pshtSheet As Worksheet

pbytNamedRange = 1

For Each pshtSheet In ActiveWindow.SelectedSheets
' pshtSheet.Activate
For Each prngCell In Selection
Debug.Print pshtSheet.prngCell.Address(False, False, xlA1, True)
Next prngCell
Next pshtSheet
End Sub


....won't work (pshtSheet.Activate is commented out) becasue prngCell is not
a member of pshtSheet. Worksheet objects don't have a "SelectedCells"
property, even though I would consider worksheets to technically have
selected cells (XL/VBA might not consider that).

Is the only way to access those cells and alter them to make their sheet
active?

Thanks again for all of your help,

Conan





"Jim Thomlinson" wrote in message
...
No you will not be able to group and update via a macro. You are correct
in
your assessment to loop through the sheets and update them individually...

--
HTH...

Jim Thomlinson


"Conan Kelly" wrote:

Hello all,

If I run the following code on "grouped" sheets (more than one sheet
selected), the selected cells on ONLY the active sheet will be
changed...all
other selected sheets will remain unchanged. If I were to change these
cells manually, all selected sheets will be changed.



Sub ReplaceReferences()
Dim prngCell As Range
Dim pbytNamedRange As Byte
Dim pbytIndex As Byte

pbytNamedRange = 1
pbytIndex = 1

For Each prngCell In Selection
prngCell.Formula = "'=" & Range("rngStartBals." &
pbytNamedRange).Cells(pbytIndex).Address(True, True, xlA1, True)
' ActiveWindow.SelectedSheets.prngCell.Formula = "'=" &
Range("rngStartBals." & pbytNamedRange).Cells(pbytIndex).Address(True,
True,
xlA1, True)
pbytIndex = pbytIndex + 1
Next prngCell
End Sub



Is there some quick, simple way to get this to affect all selected sheets
or
will I have to loop through all selected sheets and then loop through
cells?
If looping through sheets then cells, no need to post modified code. I'm
pretty sure I can figure that out.

As you can tell by the commented-out line of code, I tried to qualify my
range variable with "ActiveWindow.SelectedSheets." and no workie. Hoping
for something simple like that, but will settle for looping through
sheets
if necessary.

Thanks for any help anyone can provide,

Conan Kelly








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
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Excel Programming 1 November 16th 07 10:41 PM
Effect of "Save As..." in making VBA code work, or not David J Richardson[_2_] Excel Programming 0 October 24th 07 12:03 PM
Making "examp le" become "examp_le" in a string Sworkhard Excel Programming 3 October 29th 04 09:31 PM
Making command button code "more flexible" John Wilson Excel Programming 1 August 4th 03 10:43 PM
Making command button code "more flexible" Greg Wilson[_3_] Excel Programming 0 August 4th 03 06:12 PM


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