Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Find value in Multiple Sheets

I am trying to find a vlaue in multiple sheets. It will only be
listed once. I just do not know what sheet it will appear on. Thanks
is advance for the help. I am doing this in VBA.

Thanks,
Jay
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Find value in Multiple Sheets

After rereading my post I realized that I need to clarify a couple of
things.
The sheet names are going to be four digit years 2008, 2009 etc. The
number that I want to find is going to be in one of the sheets that's
name is This Year or last year. Here is the code I have so far. It
doesn't work, but it is what I have.

Thanks,
Jay

Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim Item As String

Set TrkBk = Workbooks.Open("G:\New Items\Tracking Lists\New Item
Tracking Log.xls")

If TrkBk.Sheets(Year(Date)).Range("C4:C3000").Find(It em) Is
Nothing Then
Set Sht = TrkBk.Sheets(Year(Date) - 1)
Else
Set Sht = TrkBk.Sheets(Year(Date))
End If

ActiveSheet.Shapes("button 88").Visible = True
End Sub
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Find value in Multiple Sheets

Option Explicit
Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim myItem As String

Dim FoundCell As Range
Dim myYear As Long
Dim yCtr As Long
Dim HowManyYearsToCheck As Long

Set TrkBk = _
Workbooks.Open("G:\New Items\Tracking Lists\New Item Tracking Log.xls")

myItem = "qwer"

HowManyYearsToCheck = 2
For yCtr = (Year(Date) - 1) To (Year(Date) - 1 + HowManyYearsToCheck - 1)
Set Sht = Nothing
On Error Resume Next
Set Sht = TrkBk.Worksheets(CStr(yCtr))
On Error GoTo 0
If Sht Is Nothing Then
'worksheet doesn't exist, do nothing
Else
With Sht.Range("c4:c3000")
Set FoundCell = .Cells.Find(what:=myItem, _
after:=.Cells(.Cells.Count), _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
If FoundCell Is Nothing Then
'keep looking
Else
Exit For
End If
End With
End If
Next yCtr

If FoundCell Is Nothing Then
MsgBox myItem & " wasn't found"
Else
MsgBox Sht.Name & vbLf _
& FoundCell.Parent.Name & vbLf _
& FoundCell.Address(0, 0)
End If

'I'm not sure what this is supposed to do.
'ActiveSheet.Shapes("button 88").Visible = True
End Sub

jlclyde wrote:

After rereading my post I realized that I need to clarify a couple of
things.
The sheet names are going to be four digit years 2008, 2009 etc. The
number that I want to find is going to be in one of the sheets that's
name is This Year or last year. Here is the code I have so far. It
doesn't work, but it is what I have.

Thanks,
Jay

Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim Item As String

Set TrkBk = Workbooks.Open("G:\New Items\Tracking Lists\New Item
Tracking Log.xls")

If TrkBk.Sheets(Year(Date)).Range("C4:C3000").Find(It em) Is
Nothing Then
Set Sht = TrkBk.Sheets(Year(Date) - 1)
Else
Set Sht = TrkBk.Sheets(Year(Date))
End If

ActiveSheet.Shapes("button 88").Visible = True
End Sub


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Find value in Multiple Sheets

Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim Item As String

Set TrkBk = Workbooks.Open("G:\New Items\Tracking Lists\New Item
Tracking Log.xls")

If TrkBk.Sheets(Year(Date)).Range("C4:C3000").Find(It em) Is
Nothing Then
Set Sht = TrkBk.Sheets(Year(Date) - 1)
Else
Set Sht = TrkBk.Sheets(Year(Date))
End If

ActiveSheet.Shapes("button 88").Visible = True
End Sub

jlclyde wrote:

After rereading my post I realized that I need to clarify a couple of
things.
The sheet names are going to be four digit years 2008, 2009 etc. The
number that I want to find is going to be in one of the sheets that's
name is This Year or last year. Here is the code I have so far. It
doesn't work, but it is what I have.

Thanks,
Jay

Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim Item As String

Set TrkBk = Workbooks.Open("G:\New Items\Tracking Lists\New Item
Tracking Log.xls")

If TrkBk.Sheets(Year(Date)).Range("C4:C3000").Find(It em) Is
Nothing Then
Set Sht = TrkBk.Sheets(Year(Date) - 1)
Else
Set Sht = TrkBk.Sheets(Year(Date))
End If

ActiveSheet.Shapes("button 88").Visible = True
End Sub


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Find value in Multiple Sheets

Ignore this message. It's just a copy of your original code.

Dave Peterson wrote:

Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim Item As String

Set TrkBk = Workbooks.Open("G:\New Items\Tracking Lists\New Item
Tracking Log.xls")

If TrkBk.Sheets(Year(Date)).Range("C4:C3000").Find(It em) Is
Nothing Then
Set Sht = TrkBk.Sheets(Year(Date) - 1)
Else
Set Sht = TrkBk.Sheets(Year(Date))
End If

ActiveSheet.Shapes("button 88").Visible = True
End Sub

jlclyde wrote:

After rereading my post I realized that I need to clarify a couple of
things.
The sheet names are going to be four digit years 2008, 2009 etc. The
number that I want to find is going to be in one of the sheets that's
name is This Year or last year. Here is the code I have so far. It
doesn't work, but it is what I have.

Thanks,
Jay

Sub AddFormsRunButton()
Dim TrkBk As Workbook
Dim SentPrepRow As Long
Dim Sht As Worksheet
Dim Item As String

Set TrkBk = Workbooks.Open("G:\New Items\Tracking Lists\New Item
Tracking Log.xls")

If TrkBk.Sheets(Year(Date)).Range("C4:C3000").Find(It em) Is
Nothing Then
Set Sht = TrkBk.Sheets(Year(Date) - 1)
Else
Set Sht = TrkBk.Sheets(Year(Date))
End If

ActiveSheet.Shapes("button 88").Visible = True
End Sub


--

Dave Peterson


--

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
find replace in multiple sheets based on namebox gabitzu Excel Discussion (Misc queries) 2 December 19th 06 11:30 AM
Sum values in multiple sheets using Lookup to find a text match CheriT63 Excel Worksheet Functions 7 December 4th 05 02:33 AM
Find values from cells in multiple sheets asubramaniam Excel Worksheet Functions 2 July 24th 05 01:50 PM
how do i find data in multiple sheets in excel Karline Excel Discussion (Misc queries) 2 May 13th 05 03:33 PM
how do i find data in multiple sheets in excel Karline Excel Worksheet Functions 2 May 13th 05 03:26 PM


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