Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default code to find stuff in each sheet?

I want to write some code to loop through all the w/sheets in the
current open workbook and inspect various columns within each sheet.

I understand how to define and loop through the worksheet collection, I
just don't know how to code the 'inspection' part ... so I've got the
outline as follows:

Private Sub Worksheet_Activate()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
... my code to inspect, for example, column P within the wsheet
defined by sh and return a value based on various criteria

Next

but not the detail.

Anyone help....

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default code to find stuff in each sheet?

Hi,
Simple example of using FIND on column P. If you have multiple
criteria then you will probably use IF ..THEN .. ELSE constructs rather than
(or in conjunction with ) FIND.

Without knowing your criteria it is difficult to more specific.

HTH

Private Sub Worksheet_Activate()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
myValue = "ABC"
With sh.Columns("P:P")
' example of FIND ......look for "ABC" and replace by "XYZ"
Set c = .Find(myValue, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
' your code here
c.Value = "XYZ"
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With
Next

End Sub

" wrote:

I want to write some code to loop through all the w/sheets in the
current open workbook and inspect various columns within each sheet.

I understand how to define and loop through the worksheet collection, I
just don't know how to code the 'inspection' part ... so I've got the
outline as follows:

Private Sub Worksheet_Activate()
Dim sh As Worksheet

For Each sh In ActiveWorkbook.Worksheets
... my code to inspect, for example, column P within the wsheet
defined by sh and return a value based on various criteria

Next

but not the detail.

Anyone help....


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default code to find stuff in each sheet?

Hi,

That does start to help me ...

But, instead of the find, how would I loop through each of the cells
in, for example, column P and inspect them one at a time?

I', not looking for a specific value particularly, I'm trying to find a
cell which satifies a certain criteria e.g. it must come before the
next zero value ...

TIA

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default code to find stuff in each sheet?

Dim rng as Range, cell as Range
set rng = Range(cells(1,"P"),Cells(rows.count,"P").End(xlup) )
for each cell in rng
if cell.Offset(1,0).Value = 0 then
msgbox cell.Address
exit for
end if
Next

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
Hi,

That does start to help me ...

But, instead of the find, how would I loop through each of the cells
in, for example, column P and inspect them one at a time?

I', not looking for a specific value particularly, I'm trying to find a
cell which satifies a certain criteria e.g. it must come before the
next zero value ...

TIA



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default code to find stuff in each sheet?

thanks Tom.

could I put the above code insdie the loop that 'reads' thru all the
worksheets?

or do I have add some reference to the worksheet?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default code to find stuff in each sheet?

Sub InspectSheets
Dim rng as Range, cell as Range
Dim sh as Worksheet

for each sh in Worksheets
set rng = sh.Range(sh.cells(1,"P"),sh.Cells(rows.count,"P"). End(xlup))
for each cell in rng
if cell.Offset(1,0).Value = 0 then
msgbox cell.Address(0,0,xlA1,True)
exit for
end if
Next cell
Next sh
End Sub

Obviously tailor the code to fit the condition you are looking for.

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
thanks Tom.

could I put the above code insdie the loop that 'reads' thru all the
worksheets?

or do I have add some reference to the worksheet?



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default code to find stuff in each sheet?

Tom,

I managed to tailor the code to get it to do exactly what I wanted.

thanks a lot for your help!

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
Create Sheet & Copy Stuff littleredhairedgirl Excel Worksheet Functions 0 October 24th 09 01:22 PM
sorting and adding cells in different work sheet? (hard stuff) doyree Excel Discussion (Misc queries) 8 February 13th 08 12:37 AM
Code using A sheet to find a number Mike Excel Discussion (Misc queries) 6 March 8th 07 07:24 PM
Find and Replace ROUNDUP(stuff, 0) [email protected] Excel Worksheet Functions 3 October 25th 06 09:00 PM
were can i find stuff on writting marcos help Excel Discussion (Misc queries) 1 February 24th 06 11:48 PM


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