View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default Find the correct sheet then find a value on that sheet

On Monday, November 18, 2013 1:28:35 AM UTC-8, Claus Busch wrote:
Hi Howard,



Am Mon, 18 Nov 2013 00:47:14 -0800 (PST) schrieb Howard:
try:


Sub SearchAOne()

Dim FindDate As Date

Dim FindStore As String 'Dimmed but not used yet

Dim RngD As Range

Dim RngS As Range 'Dimmed but not used yet

Dim ws As Worksheet

Dim cnt As Integer

Dim LRow As Long

FindStore = Sheets("Sheet1").Range("D4").Value 'Dimmed but not used

yet

FindDate = Sheets("Sheet1").Range("D8")



If FindDate 0 Then

For Each ws In ThisWorkbook.Worksheets

With ws.Range("A1")

Set RngD = .Find(FindDate, LookIn:=xlValues)

If Not RngD Is Nothing Then

Application.Goto RngD

Exit For

End If

End With

Next ws

End If

If Not RngD Is Nothing Then

With ActiveSheet

LRow = .Cells(.Rows.Count, 3).End(xlUp).Row

Set RngS = .Range("C5:C" & LRow).Find(FindStore, _

LookIn:=xlValues)

If Not RngS Is Nothing Then

RngS.Select

Else

MsgBox "No value for FindStore"

End If

End With

Else

MsgBox "No date found"

End If

End Sub





Regards

Claus B.


Tried the code and got a Type Mismatch. I suspected the date cell as I was using a string in my earlier tests.

Formatted The A1 cells as date along with the Sheet 1 D8 cell.
Entered a date in Sheet 1 and an identical date in sheet 3 A1.

Tested with this formula and it returned true. (Where A1 is on sheet 3)
=A1=Sheet1!D8

Code returns the message box "No Date found"

So I reformatted Sheet 3, A1 and Sheet 1, D8 to General and entered "FindMe" in each cell.

Changed FindDate to string: Dim FindDate As String 'Date

Changed this If FindDate 0 Then

To

If FindDate < "" Then

Code works.

Making it find the date seems to be a problem.

Howard