I am trying to convert all string dates to number for an entire column. Based on this Question, I initially tried:
.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)) =CDate(.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)))
then I thought I may need value, so I tried the following:
.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)).value =CDate(.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)).value)
.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)) =CDate(.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)).value)
.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)).value =CDate(.range(.cells(headerrow+1, ImpCol.column),.cells(LastRow, ImpCol.column)))
So then I did some more research, found this question, and I am guessing that I need to go cell by cell so I tried setting up a for each loop:
'I tired both dims spearately, one at a time. just listing what I have tried.
Dim rngCell as range
Dim rngCell as variant
For Each rngCell In Source.Worksheets("Sheet1").Columns(ImpCol.Column)
If rngCell.Row > HeaderRow Then rngCell.Value = CDate(rngCell.Value)
Next rngCell
When I step through, ImpCol.Column has a value of 7 as I expected. Since I was just supplying a single column I was expecting rngCell to take the value of the contents of each cell one at a time. Instead it grabs the whole column, performs one check, and does not loop.
I know how to do it in a For X= HeaderRow +1 to LastRow
, but I do not understand how to make FOR EACH
work in this case.
What adjustment do I need to make to have it step through each cell in a FOR EACH
loop?