I am a total newbie to excel vba, and I am currently stuck on this problem. Hopefully someone can point me in the right direction.
I am searching a range of cells starting at the last day of the month. For example:
varEOM = "31"
varMM = "03"
varYYYY = "2006"
If there is no data for the 31st of March 2006, then it will not be in the list/column. Therefore, I want to programmatically look back to the 30th, 29th and so forth. I am looking back at 10 year's worth of data.
Also, due to the nature of the data, varYYYY, varMM and varEOM are strings rather than Integers, so I think I need to convert them from Strings to Integers at some point.
I am having issues finding a logical way to loop through and decrement a counter until I hit a valid date.
Here is the code I have so far:
Dim varYYYY As String, varMM As String, varEOM As String, varInteger As Integer, varString As String
varEOM = "31"
varMM = "03"
varYYYY = "2006"
varInteger = CInt(varEOM)
varValueToFind = varYYYY & varMM & varEOM
Do Until Not IsNull(el)
Set rng = Range("b1", Range("b65536").End(xlUp))
' Find the cell reference on the varValuetoFind
Set el = rng.Find(varValueToFind, LookIn:=xlValues)
Set fl = rng.Find(varValueToFind, LookAt:=xlPart)
Debug.Print varYYYY
Debug.Print varMM
Debug.Print varEOM
Debug.Print el
Debug.Print fl.Address
Debug.Print varValueToFind
varInteger = varInteger - 1
Debug.Print varInteger
Loop
If there is data on the 31st then the code works. But if there is no data on the 31st and I need to revert to finding 20060330, then the code breaks down.
Thanks in advance. Any help would be appreciated.