VBA Find Function

smartpat19

Board Regular
Joined
Sep 3, 2014
Messages
114
HI All,

Working on my first find function. I am trying to return the range. The formatting is dates and I am trying the find what cell the date is in row 7. Right now I am returning nothing.


VBA Code:
Sub Retainage_Macro()

Dim proforma As Workbook
Set proforma = ActiveWorkbook
Dim master As Workbook

Dim Current_Month As Range

Set Sht = Sheets("Project Summary")
Set cfs = Sheets("Cash Flow Template")

Start = cfs.Range("E1").Value

Set Current_Month = cfs.Range("7:7").Find(What:=Start, Lookat:=xlWhole, MatchCase:=False)

MsgBox (Current_Month)

Thank you
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Does it return anything if you change the last line to:
VBA Code:
MsgBox Current_Month.Address

Does either the dates in cell E1 or row 7 actually have a time component to them?
 
Upvote 0
Does it return anything if you change the last line to:
VBA Code:
MsgBox Current_Month.Address

Does either the dates in cell E1 or row 7 actually have a time component to them?
No Time component. The dates are all populated using the edate formula and are formatted to look like "MMM-YY"
 
Upvote 0
Does this work?
VBA Code:
Sub Retainage_Macro()
Dim proforma As Workbook
Dim master As Workbook
Dim sht As Worksheet
Dim cfs As Worksheet
Dim Current_Month As Range
Dim Res As Variant
Dim Start As Date

    Set proforma = ActiveWorkbook
        
    Set sht = Sheets("Project Summary")
    Set cfs = Sheets("Cash Flow Template")
    
    Start = cfs.Range("E1").Value
    
    Res = Application.Match(Start, cfs.Rows(7), 0)
    
    If Not IsError(Res) Then
        Set Current_Month = cfs.Cells(7, Res)
        MsgBox Current_Month.Value
    Else
        MsgBox "Start not found!"
    End If
 
Upvote 0
Does this work?
VBA Code:
Sub Retainage_Macro()
Dim proforma As Workbook
Dim master As Workbook
Dim sht As Worksheet
Dim cfs As Worksheet
Dim Current_Month As Range
Dim Res As Variant
Dim Start As Date

    Set proforma = ActiveWorkbook
       
    Set sht = Sheets("Project Summary")
    Set cfs = Sheets("Cash Flow Template")
   
    Start = cfs.Range("E1").Value
   
    Res = Application.Match(Start, cfs.Rows(7), 0)
   
    If Not IsError(Res) Then
        Set Current_Month = cfs.Cells(7, Res)
        MsgBox Current_Month.Value
    Else
        MsgBox "Start not found!"
    End If
Only receiving "Start not found". Is it the formulas in the cells or formatting? Thank you for your help!
 
Upvote 0
Update:
VBA Code:
Sub Retainage_Macro()

Dim proforma As Workbook
Set proforma = ActiveWorkbook
Dim master As Workbook

Dim Current_Month As Range

Set sht = Sheets("Project Summary")
Set cfs = Sheets("Cash Flow Template")

Start = cfs.Range("E1").Value

Set Current_Month = cfs.Range("7:7").Find(What:=Start, Lookat:=xlWhole, MatchCase:=False)

MsgBox Current_Month.Address

End Sub

When Formatting the cell to Short Date, this macro works. However, the current formatting of "MMM-YY" does not work. How Can i adjust this to work on "MMM-YY" Formatting?

Thank you for your help
 
Upvote 0
smartpat19

Excel VBA has always had problems finding dates whether you use the Find method or Application.Match.

In my code you could try wrapping Start in CDbl, of CInt.
VBA Code:
    Res = Application.Match(CDbl(Start), cfs.Rows(7), 0)
 
Upvote 0
Solution
smartpat19

Excel VBA has always had problems finding dates whether you use the Find method or Application.Match.

In my code you could try wrapping Start in CDbl, of CInt.
VBA Code:
    Res = Application.Match(CDbl(Start), cfs.Rows(7), 0)
Thank you!! This works great! Thank you!
 
Upvote 0

Forum statistics

Threads
1,214,929
Messages
6,122,314
Members
449,081
Latest member
tanurai

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