Excel Find and .FIND Method issue

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
549
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
 

Some videos you may like

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.

Weaver

Well-known Member
Joined
Sep 10, 2008
Messages
5,196
I think it could be related to the formatting. Dates are stored as a value, but displayed as a date.
 

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
549
I have checked the formatting the lookup date is formatted exactly the same as in the lookup range.
 

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
549

ADVERTISEMENT

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
 

purceld2

Well-known Member
Joined
Aug 18, 2005
Messages
549
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 -->
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
45,918
Office Version
365
Platform
Windows
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. :)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,731
Messages
5,513,068
Members
408,935
Latest member
Jmtramos

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top