I'm looking to run an Excel VBA looping code that searches through column 'G' searching for any dates that appears, and then does something with that date, and then moves on to the next date that appears in the selection. My problem is that once the code reaches the bottom of the worksheet (or the end of the selection), it just restarts back at the top of the section and loops all over again. I need the code to stop once it reaches the end of the document (and in this case, the end of the selection). Any ideas on how to accomplish this?
Here is my code so far:
Sub Move_Dates_To_Column()
Dim Cell As Range
Columns("A:A").Select
Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Set SelectedRange = Sheets("Sheet1").Range("G1:G9000")
Set FindDate = Sheets("Sheet1").Range("G1:G9000").Find(What:="**/**/****", LookIn:=xlFormulas)
' Do Until FindDate Is Nothing
' If Not FindDate Is Nothing Then
For Each Cell In SelectedRange
Cell.Select
If Not IsEmpty(ActiveCell.Value) Then
Cells.Find(What:="**/**/****", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
ActiveCell.Copy
ActiveCell.Offset(2, -7).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(2, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
ActiveCell.Offset(1, 0).PasteSpecial xlPasteValuesAndNumberFormats
'ActiveCell.Offest(1, 0).Select
End If
Next Cell
End Sub
*Just a note, there are blank spaces throughout this range. The range should be "Range(G:G)"