locate the cell address of dates formated with mmm-yy

anilsharaf

New Member
Joined
Apr 8, 2014
Messages
43
Office Version
  1. 2007
Platform
  1. Windows
In sheet ePay Column A there are month Names of the Finencial Year. Mar-21 to Jan-22. I tried several code snippests but my code fails in the loop. Window7, Excel 2007, Date system Date Formate is United Kingdom short date dd/mm/yy Long date formate is dd-mmmm-yyyy. I used the codes: when I do this in User Interface Find all works. The sheet is a downloaded sheet from ePay Database. Actually I have to retrive data from many sheets. I have done this locating the DDOCode 62014 in Column A (A25). But some times it is not available. But the Pay of Month is always there. So I want to retrive the data locating cell in which Pay of Months are entered.
I would be greatful for your help. Thanks in advance.
The Code is:
VBA Code:
Sub XX_Failed_XXDateBasedSearchWriteAmountToSheet_MyCopiedData()

NextEmployeeRow = 11

LastRow = ActiveSheet.UsedRange.Rows.Count - 4



1 'read the number of employees from sheet finding "Dates in mmm-yy Format"

With ActiveSheet.Range("A" & NextEmployeeRow & ":A" & LastRow)



'Search is based on Date Formate of Sheet

Application.FindFormat.Clear

Application.FindFormat.NumberFormat = "mmm-yy"

Set cell = .Find(What:="", LookIn:=xlFormulas, LookAt:= _

xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _

, SearchFormat:=True)

x = cell

If Not cell Is Nothing Then

firstAddress = cell.Address

NextEmployeeRow = Range(cell.Address).Row + 1

Do

TotalEntries = TotalEntries + 1

EmId = Range(cell.Address).Offset(-2, 1)

EmNm = Range(cell.Address).Offset(2, 1)

'Range(cell.Address).Offset(-3, 1).Resize(7, 13).Select

'cell.Value = 5

Set cell = .FindNext

x = cell

Loop While Not cell Is Nothing And cell.Address <> firstAddress

End If

End With

end sub
The Mini Sheet is:
Book1
ABCDEFGHIJKLMN
11Sr.No.BasicStagnationIncTrans.Allow.WashingAllowSp.PoliceAllowConn.Ch.AllowWaterAllowGrossSalaryGPF/DPF/Tier1GrainRecGISTotalDedn.
12EmployeeIDD.PayInterimReliefDepu.AllowCashierAllowBigularAllowSpecialAllowNewsPrAllowG/DPF/CPS.RcComputerRecPLINetSalary
13EmployeeCodeGradePayOtherPayTribalAllowOtherAllowMedalAllowRobeAllowMag.AllowHB.RecPayRecHouseRent
14Pay Month YearPF/PRAN NO.NPAD.A.HRAWagesArmourAllowSumptAllowElec.AllowCarRecOtherRecWaterCharge
15Salary Taken DDOBankA/CSpecialPayAdditionalDAProjectAllowFixTADIAllowLibAllowSec.AllowCycleRecIncomeTaxMot.Vec.Char
16NamePersonalPayFeeTrainingAllowP.AaharAllowUniformAllowTeleAllow-MotorCycleRecProf.TaxOtherDed
17HonorariumCCAMedicalAllowSp.RationAllowMT.AllowH.O.Allow-FestivalRecFBFEx.PayRec
18
19
20Designation :Regular Peon, No. of Post :2, Wide Sanction Order No. and Date :F/44/Fin/,-
21123600005000027310264301802823
221000000000024487
2362001400300000000000
24Mar-211.1001E+11028326280000000
25620014115025408310000000000
26Marina0000000000
27002000000000
28
29
30223600005000027310264301803610
311000000000023700
3262001400300000000000
33Apr-211.1001E+11028326280000000
34620014115025408310000000000
35Marina000000000787
36002000000000
37
38
39323600005000027310264301802823
401000000000024487
4162001400300000000000
42May-211.1001E+11028326280000000
43620014115025408310000000000
44Marina0000000000
45002000000000
46
47
48423600005000027310264301802823
491000000000024487
5062001400300000000000
51Jun-211.1001E+11028326280000000
52620014115025408310000000000
53Marina0000000000
54002000000000
ePay1
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Your posted code doesn't compile (there's an issue with the line continuation characters). Since I use Option Explicit at the top of every module, I had to declare about 8 missing variables. It will run, but starting at A11, your code (Set cell = .Find(What:="",) does not find "" so cell is Nothing thus X = cell also fails.
Maybe you could just search the range for anything that is a date data type, like
If IsDate (CDate(Range("A23"))) Then (where the range is determined in your loop).
I think you'll find that if you put that in the vb editor immediate window as

?IsDate (CDate(Range("A23")))

"True" will be returned because the unformatted value in that cell is 44257, which is a valid date value.
 
Upvote 0
2 options
- look in column A and retrieve all blocks of cells with constants (=not empty, no formula) & that block starts > row 10 and the block is 2 cells
- look for a certain date in column A
VBA Code:
Sub MijnKolomA()

     With ActiveSheet
          Set c = .Range("A1:A" & .Range("A" & Rows.Count).End(xlUp).Row)     'usedrange of column A
          Set c1 = c.SpecialCells(xlConstants)

     'option1
          For Each ar In c1.Areas                               'loop through all the block of constants in column A
               If ar.Cells(1).Row > 10 And ar.Rows.Count = 2 Then     'startrow>10 and a block of 2 rows
                    MsgBox ar.Address & vbLf & Format(ar.Cells(1), "dd mm yyyy") & vbLf & ar.Cells(2)
               End If
          Next

     'option2
          a = c.Value2                                          'column A -> array   !!!! value2 !!!!!
          mydate = DateSerial(2021, 5, 1)                       ' a date
          r = Application.Match(CDbl(mydate), a, 0)
          If IsNumeric(r) Then MsgBox "your date " & Format(mydate, "dd-mm-yy") & " is in cell " & c.Cells(r, 1).Address
     End With

End Sub
 
Upvote 0
Just discovered that it didn't find "" for me because I didn't bother to change the date values from numbers to values formatted as mmm-yy and you had set the Find SearchFormat parameter to True. Not sure why you're looking at formulas instead of values though. I suspect you get stuck in your loop as it doesn't seem to increment anything, which must be what you meant by
I tried several code snippests but my code fails in the loop.
Sorry, I should bow out except to say that you might be able to use IsDate as suggested.
 
Upvote 0
Thanks both to respected Micron and BSALV, I am going to use the code suggested by both of you. But I just found a trick and visited the Forum to tell about that. The trick is using wild card in Find VBA. This trick does not work in Excel Interface. It works only with VBA. The trick is to find all dates formated with "mmm-yy" using the wild card. Thanks to Paul Kelly he has given a full Detail of "Find VBA" at Excel VBA Find - A Complete Guide - Excel Macro Mastery . Using (Topic 15) the wild card string "*-2?" finds all dates that I needed to search for. This The code is below. I will try codes given by both of You. Because it may give me some new idea and some new dimension. Thanks again.
Code:

VBA Code:
Sub FindDate_Formated_mmm_yy()
With ActiveSheet.Range("A:A")
.Find("*-2?", LookIn:=xlValues).Activate
Do
.FindNext(ActiveCell).Activate
Loop
End With
 End Sub
 
Upvote 0
Solution
This trick does not work in Excel Interface. It works only with VBA.
Sure it works in the Excel Interface. Select your column, press CTRL+F to bring up the Find dialog box, type *-2? in the "Find what" field, click the "Options>>" button and make sure the "Look in" drop-down is set to "Values" and that the "Match entire cell contents" check box is checked, then click the "Find All" button and follow that by pressing CTRL+A. You can now close the dialog box and the cells with the format you wanted will all be selected.
 
Upvote 0
then click the "Find All" button and follow that by pressing CTRL+A.
That's an interesting thought and i tried to incorporate that in VBA.
So i started with the macro-recorder, but that one didn't record anything of that "find"-session.
Is there a possibility to simulate all this with "Sendkey" or something similar to get at once all those cells instead of in a loop "findnext"
 
Upvote 0
I have never found a way to replicate "Find All"... whoever designed the Excel engine within VBA left that functionality out. I am not sure if SendKeys can be made to work or not.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,891
Members
449,194
Latest member
JayEggleton

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