Find first occurence of a string

DHogg

New Member
Joined
Jan 15, 2013
Messages
28
I have some data with an output similar to this:
01APR2013:10:43:41.134000

There are thousands of lines of data from various months. I want a macro which will select the cell in a column which is the first day of the month. So basically, work out what the first day of the current month is, and find the first result in the column so I can then select all data below that and copy/paste to another location. I thought using something like search, today, day, and month function would work, but some of these are not in VBA.

Any ideas?
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Uisng formula:

Excel 2010
ABC
104APR2013:10:43:41.13400001APR2013:10:43:41.134012
204APR2013:10:43:41.134001
304APR2013:10:43:41.134002
404APR2013:10:43:41.134003
504APR2013:10:43:41.134004
604APR2013:10:43:41.134005
702APR2013:10:43:41.134006
804APR2013:10:43:41.134007
904APR2013:10:43:41.134008
1004APR2013:10:43:41.134009
1104APR2013:10:43:41.134010
1204APR2013:10:43:41.134011
1301APR2013:10:43:41.134012
1401APR2013:10:43:41.134013
1501APR2013:10:43:41.134014
1601APR2013:10:43:41.134015
1710APR2013:10:43:41.134016
1801APR2013:10:43:41.134017
Sheet1
Cell Formulas
RangeFormula
C1{=INDEX($A$1:$A$18,MATCH(DATE(YEAR(TODAY()),MONTH(TODAY()),1),--LEFT($A$1:$A$18,9),0))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
I have some data with an output similar to this:
01APR2013:10:43:41.134000

There are thousands of lines of data from various months. I want a macro which will select the cell in a column which is the first day of the month. So basically, work out what the first day of the current month is, and find the first result in the column so I can then select all data below that and copy/paste to another location. I thought using something like search, today, day, and month function would work, but some of these are not in VBA.

Any ideas?
Give this macro a try...
Code:
Sub FindFirstOfCurrentMonth()
  On Error Resume Next
  Columns("A").Find("01" & Format(Date, "mmm") & Year(Now) & "*", Cells(Rows.Count, _
                    "A"), LookAt:=xlPart, SearchDirection:=xlNext).Select
  If Err.Number Then MsgBox "Cannot find first day of this month!"
  On Error GoTo 0
End Sub
 
Upvote 0
Wow, two great solutions. Robert Mika, would you mind explaining(or try to) the formula? The match part kind of lost me. I'm normally good with long array formulas but not that one.
 
Upvote 0
Just giving a try,

In C2

=VLOOKUP(TEXT(EOMONTH(LEFT(A2,9),-1)+1,"ddmmmyyyy")&"*",A:A,1,0)
 
Upvote 0

Forum statistics

Threads
1,203,174
Messages
6,053,929
Members
444,694
Latest member
JacquiDaly

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