Excel Find and .FIND Method issue

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
586
Office Version
  1. 2013
Platform
  1. Windows
I a issue with the Excel FIND and the .FIND Method. I have some VBA that uses the .FIND method which looks for a date along a row of dates. See below. The code would not find the date. So i tried finding it using the Excel FIND and it would not find it also.

So in the options I change the lookin: from Values to formula and then it found it. I then changed the code to do the same and it now finds it. But what is puzzling is that the dates have be typed in as values and are not formulas, am I missing something.

Excel Workbook
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1Lookup Date16/08/201026/07/201002/08/201009/08/201016/08/201023/08/2010
2Venue CodeNetworkCount123456123456123456123456123456
3601ESS1708708736708736708708
4602ESS1708708736708736708708
sheet1
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
I think it could be related to the formatting. Dates are stored as a value, but displayed as a date.
 
Upvote 0
I have checked the formatting the lookup date is formatted exactly the same as in the lookup range.
 
Upvote 0
Code:
Sub Count_Slot_Items()
    Dim LastRow As Long
    
    Application.ScreenUpdating = False
    With Sheets("Sheet2")
    
        .Columns("A:L").Clear
        
        For c = 0 To 10 Step 2
            
            Sheets("Sheet1").Columns("B:B").Offset(, c / 2).Copy Destination:=.Range("B1").Offset(, c)
            
            .Columns("B:B").Offset(, c).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Range("A1").Offset(, c), Unique:=True
            .Columns("B:B").Offset(, c).Clear
            LastRow = .Range("A" & Rows.Count).Offset(, c).End(xlUp).Row
            
            .Range("B1").Offset(, c).Value = "Count"
            If LastRow > 1 Then
                .Range("B2").Offset(, c).Formula = "=COUNTIF(Sheet1!" & Columns(2 + c / 2).Address & "," & Range("A2").Offset(, c).Address(0, 0) & ")"
                If LastRow > 2 Then
                    .Range("B2").Offset(, c).AutoFill Destination:=.Range("B2:B" & LastRow).Offset(, c)
                End If
                .Range("B2:B" & LastRow).Offset(, c).Value = .Range("B2:B" & LastRow).Offset(, c).Value
            End If
            
        Next c
        
        ' Format cells
        Range("A1").Copy
        Range("A1", Range("A1").End(xlToRight)).PasteSpecial Paste:=xlPasteFormats
        .Select
        
    End With
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Sorry that was the wrong code correct code below

Code:
Sub Count_Slot_Items()
Dim LR As Long, i As Long, FindDate As Date
Dim Rng As Range
Application.ScreenUpdating = False
Sheets("Sheet2").Columns("A:L").Clear
FindDate = Sheets("Sheet1").Range("C1").Value
With Sheets("Sheet1").Range("D1:IV1")
Set Rng = .Find(What:=FindDate, After:=.Cells(1, .Columns.Count), LookIn:=xlValues, LookAt:=xlWhole _
, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not Rng Is Nothing Then
For i = 0 To 10 Step 2
If Range(Rng.Offset(1, i / 2), Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, _
Rng.Column + i / 2).End(xlUp)).Cells.Count > 1 Then
Range(Rng.Offset(1, i / 2), Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, _
Rng.Column + i / 2).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, _
CopyToRange:=Sheets("Sheet2").Cells(1, i + 1), Unique:=True
Sheets("Sheet2").Cells(1, i + 1).Value = "Slot " & Sheets("Sheet2").Cells(1, i + 1).Value
Sheets("Sheet2").Cells(1, i + 2).Value = "Count"
LR = Sheets("Sheet2").Cells(Sheets("Sheet2").Rows.Count, i + 1).End(xlUp).Row
If LR > 2 Then
For j = 2 To LR
Sheets("Sheet2").Cells(j, i + 2).Value = WorksheetFunction.CountIf( _
Range(Rng.Offset(1, i / 2), Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, _
Rng.Column + i / 2).End(xlUp)), _
Sheets("Sheet2").Cells(j, i + 1).Value)
Next j
Else
Sheets("Sheet2").Cells(2, i + 2).Value = WorksheetFunction.CountIf( _
Range(Rng.Offset(1, i / 2), Sheets("Sheet1").Cells(Sheets("Sheet1").Rows.Count, _
Rng.Column + i / 2).End(xlUp)), _
Sheets("Sheet2").Cells(2, i + 1).Value)
End If
Else
Sheets("Sheet2").Cells(1, i + 1).Value = "Slot " & Rng.Offset(1, i / 2).Value
Sheets("Sheet2").Cells(1, i + 2).Value = "Count"
End If
Next i
End If
End With
Sheets("Sheet2").Columns.AutoFit
Application.ScreenUpdating = True
End Sub
<!-- / message --><!-- sig -->
 
Upvote 0
Sorry that was the wrong code correct code below
Do you know that for 10 minutes you can edit your post? So you could have edited the previous post and removed the wrong code and replaced it with the correct code. Would have made the thread simpler. :)
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top