ChristineWisc
New Member
- Joined
- Oct 18, 2018
- Messages
- 4
I'm a complete novice at this, but have stumbled through up until this hiccup.
Trying to create code to check each cell in a column and if there is data in the cell, convert the data to a US date (currently coming in as text and European format). I got the date code to work in a different macro that has data in every cell of the column, but am stuck when it comes to running a check on each cell.
Here is what I'm trying and it will do the first cell, but then errors on the dte = Split(Left(cell.Text, InStr(cell.Text, " ") - 1), "/").
Sub EndDate_convert()
Dim cell As Range
'loop through each cell in a cell range
For Each cell In ActiveSheet.Range("i2:i65536")
If cell = 0 Then
'do nothing
Else
Dim dte() As String
dte = Split(Left(cell.Text, InStr(cell.Text, " ") - 1), "/")
cell.Value = DateSerial(dte(2), dte(1), dte(0)) + CDate(Mid(cell.Text, InStr(cell.Text, " ") + 1))
End If
Next cell
End Sub
Thanks.
Trying to create code to check each cell in a column and if there is data in the cell, convert the data to a US date (currently coming in as text and European format). I got the date code to work in a different macro that has data in every cell of the column, but am stuck when it comes to running a check on each cell.
Here is what I'm trying and it will do the first cell, but then errors on the dte = Split(Left(cell.Text, InStr(cell.Text, " ") - 1), "/").
Sub EndDate_convert()
Dim cell As Range
'loop through each cell in a cell range
For Each cell In ActiveSheet.Range("i2:i65536")
If cell = 0 Then
'do nothing
Else
Dim dte() As String
dte = Split(Left(cell.Text, InStr(cell.Text, " ") - 1), "/")
cell.Value = DateSerial(dte(2), dte(1), dte(0)) + CDate(Mid(cell.Text, InStr(cell.Text, " ") + 1))
End If
Next cell
End Sub
Thanks.