Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
J@Y J@Y is offline
external usenet poster
 
Posts: 127
Default Need help on code - Macro on multiple worksheets

Sub SheetSub()

Dim cel As Range
Dim myStr As String

For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

For Each cel In Selection
If cel.HasFormula = True Then
If Not cel.Formula Like "=ROUND(*" Then
myStr = Right(cel.Formula, Len(cel.Formula) - 1)
cel.Value = "=ROUND(" & myStr & "," & "3" & ")"
End If
End If
Next
Next sh

End Sub

I am trying to have a macro that goes through all Sheets 1-3 and add
=Round() infront of a selection of cells. Right now, the code only performs
the function on the sheet I am currently on.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,290
Default Need help on code - Macro on multiple worksheets

Sub SheetSub()
Dim cel As Range
Dim myStr As String

Dim Sh As Object
Dim rng As Excel.Range
Set rng = Selection

For Each Sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
For Each cel In Sh.Range(rng.Address)
If cel.HasFormula = True Then
If Not cel.Formula Like "=ROUND(*" Then
myStr = Right(cel.Formula, Len(cel.Formula) - 1)
cel.Value = "=ROUND(" & myStr & "," & "3" & ")"
End If
End If
Next
Next 'Sh
End Sub
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



"J@Y"
wrote in message
Sub SheetSub()
Dim cel As Range
Dim myStr As String
For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
For Each cel In Selection
If cel.HasFormula = True Then
If Not cel.Formula Like "=ROUND(*" Then
myStr = Right(cel.Formula, Len(cel.Formula) - 1)
cel.Value = "=ROUND(" & myStr & "," & "3" & ")"
End If
End If
Next
Next sh
End Sub

I am trying to have a macro that goes through all Sheets 1-3 and add
=Round() infront of a selection of cells. Right now, the code only performs
the function on the sheet I am currently on.
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Need help on code - Macro on multiple worksheets

So it's based on the current selection in each sheet--and each sheet can have
different cells selected?

If yes:

Option Explicit

Sub SheetSub()

Dim cel As Range
Dim myStr As String
Dim sh As Worksheet
For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))
sh.Select
For Each cel In Selection
If cel.HasFormula = True Then
If Not cel.Formula Like "=ROUND(*" Then
myStr = Right(cel.Formula, Len(cel.Formula) - 1)
cel.Value = "=ROUND(" & myStr & "," & "3" & ")"
End If
End If
Next cel
Next sh


End Sub



J@Y wrote:

Sub SheetSub()

Dim cel As Range
Dim myStr As String

For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet3"))

For Each cel In Selection
If cel.HasFormula = True Then
If Not cel.Formula Like "=ROUND(*" Then
myStr = Right(cel.Formula, Len(cel.Formula) - 1)
cel.Value = "=ROUND(" & myStr & "," & "3" & ")"
End If
End If
Next
Next sh

End Sub

I am trying to have a macro that goes through all Sheets 1-3 and add
=Round() infront of a selection of cells. Right now, the code only performs
the function on the sheet I am currently on.


--

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
MACRO AND MULTIPLE WORKSHEETS Mel Excel Worksheet Functions 8 January 21st 07 02:53 PM
Macro Help (Uppercase multiple ranges?) Ken Excel Discussion (Misc queries) 14 December 2nd 06 07:23 PM
Macro referencing multiple worksheets JULZ Excel Discussion (Misc queries) 1 October 9th 06 07:46 PM
Can someone help me put psuedo code into actual excel macro?? bxc2739 Excel Discussion (Misc queries) 1 April 22nd 06 02:58 PM
CREATE MACRO TO COPY MULTIPLE WORKSHEETS Bewilderd jim Excel Discussion (Misc queries) 5 March 3rd 05 10:00 PM


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