Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Loop through found value

I have this code that I want to loop through and format each found
value, not just the firtst one, How?

Sub ByPerson()
'
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=4, Function:=xlSum,
TotalList:=Array(9, 22), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2

Set Rng = ActiveSheet.Range("D:D").Find(What:="Total", _
After:=Range("D"
& Rows.Count), _

LookIn:=xlFormulas, _
LookAt:=xlPart, _

SearchOrder:=xlByRows, _

SearchDirection:=xlNext, _
MatchCase:=False)
Rng.NumberFormat = "General"
End Sub

TIA Greg

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Loop through found value

Sub ByPerson()
'
Dim rng as Range, sAddr as String
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Sort Key1:=Range("D2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=4, _
Function:=xlSum,
TotalList:=Array(9, 22), _
Replace:=True, _
PageBreaks:=False, _
SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
With ActiveSheet.Range("D:D")
Set Rng = .Find(What:="Total", _
After:=Range("D" & Rows.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
if not rng is nothing then
sAddr = rng.Address
do
Rng.NumberFormat = "General"
set rng = .FindNext(rng)
loop while rng.Address < sAddr
End With
End Sub

I am not sure you are formatting the correct cell. the cells you find
contain the word total indicating they contain text. Perhaps you want
something like

rng.Offset(0,1).NumberFormat = "General"
to format column E entries (as an example)
Just a thought

--
Regards,
Tom Ogilvy

"GregR" wrote:

I have this code that I want to loop through and format each found
value, not just the firtst one, How?

Sub ByPerson()
'
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=4, Function:=xlSum,
TotalList:=Array(9, 22), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2

Set Rng = ActiveSheet.Range("D:D").Find(What:="Total", _
After:=Range("D"
& Rows.Count), _

LookIn:=xlFormulas, _
LookAt:=xlPart, _

SearchOrder:=xlByRows, _

SearchDirection:=xlNext, _
MatchCase:=False)
Rng.NumberFormat = "General"
End Sub

TIA Greg


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Loop through found value

This should do it for you. ( you sould probably change the Header:=xlGuess to
xlYes or xlNo)...

Sub ByPerson()
Dim rng As Range
Dim strFirstAddress As String

With Selection
.QueryTable.Refresh BackgroundQuery:=False
.Sort Key1:=Range("D2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
.Subtotal GroupBy:=4, _
Function:=xlSum, _
TotalList:=Array(9, 22), _
Replace:=True, _
PageBreaks:=False, _
SummaryBelowData:=True
End With
ActiveSheet.Outline.ShowLevels RowLevels:=2

Set rng = ActiveSheet.Range("D:D").Find(What:="Total", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)

If Not rng Is Nothing Then
strFirstAddress = rng.Address
Do
rng.NumberFormat = "General"
Set rng = ActiveSheet.Range("D:D").FindNext(rng)
Loop Until rng.Address = strFirstAddress
End If
End Sub
--
HTH...

Jim Thomlinson


"GregR" wrote:

I have this code that I want to loop through and format each found
value, not just the firtst one, How?

Sub ByPerson()
'
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=4, Function:=xlSum,
TotalList:=Array(9, 22), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2

Set Rng = ActiveSheet.Range("D:D").Find(What:="Total", _
After:=Range("D"
& Rows.Count), _

LookIn:=xlFormulas, _
LookAt:=xlPart, _

SearchOrder:=xlByRows, _

SearchDirection:=xlNext, _
MatchCase:=False)
Rng.NumberFormat = "General"
End Sub

TIA Greg


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default Loop through found value

On Mar 2, 9:30 am, Jim Thomlinson <James_Thomlin...@owfg-Re-Move-
This-.com wrote:
This should do it for you. ( you sould probably change the Header:=xlGuess to
xlYes or xlNo)...

Sub ByPerson()
Dim rng As Range
Dim strFirstAddress As String

With Selection
.QueryTable.Refresh BackgroundQuery:=False
.Sort Key1:=Range("D2"), _
Order1:=xlAscending, _
Header:=xlGuess, _
OrderCustom:=1, _
MatchCase:=False, _
Orientation:=xlTopToBottom
.Subtotal GroupBy:=4, _
Function:=xlSum, _
TotalList:=Array(9, 22), _
Replace:=True, _
PageBreaks:=False, _
SummaryBelowData:=True
End With
ActiveSheet.Outline.ShowLevels RowLevels:=2

Set rng = ActiveSheet.Range("D:D").Find(What:="Total", _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
MatchCase:=False)

If Not rng Is Nothing Then
strFirstAddress = rng.Address
Do
rng.NumberFormat = "General"
Set rng = ActiveSheet.Range("D:D").FindNext(rng)
Loop Until rng.Address = strFirstAddress
End If
End Sub
--
HTH...

Jim Thomlinson



"GregR" wrote:
I have this code that I want to loop through and format each found
value, not just the firtst one, How?


Sub ByPerson()
'
Selection.QueryTable.Refresh BackgroundQuery:=False
Selection.Sort Key1:=Range("D2"), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Selection.Subtotal GroupBy:=4, Function:=xlSum,
TotalList:=Array(9, 22), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2


Set Rng = ActiveSheet.Range("D:D").Find(What:="Total", _
After:=Range("D"
& Rows.Count), _


LookIn:=xlFormulas, _
LookAt:=xlPart, _


SearchOrder:=xlByRows, _


SearchDirection:=xlNext, _
MatchCase:=False)
Rng.NumberFormat = "General"
End Sub


TIA Greg- Hide quoted text -


- Show quoted text -


Tom, Jim and Don thank you very much for your help.

Greg



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
Stop a loop when certain data is found jsmith Excel Discussion (Misc queries) 3 June 2nd 08 10:12 PM
Stop the loop when found. hfazal Excel Programming 1 February 16th 06 11:57 PM
End a loop if text is not found Ernesto[_3_] Excel Programming 2 August 19th 05 10:33 PM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM
Loop to change cell color based on found value? gaba Excel Programming 3 November 3rd 04 02:33 PM


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