D
D. Stacy
I have columns of text data representing military time (i.e. 1500, 900, 730,
45). The below code shell is designed to determine how many digits are
present and then perform come "action". I need to write the code for the
"action", now that the rest of this is working.
The desired output would look like : 3:00 PM, 9:00 AM, 7:30 AM, 12:45 AM
In excel, using formulas, this is accomplished using a mega formula
consisting of a lot of if statements, etc. etc. And it invloves inserting
columns in the native data to accept the reformed data. My goal is to simply
select the columns that need to be reformed and then run the code.
Sub ConfigureTimeData()
' Converts text time data to 4 digit time data
Dim ConstantCells As Range
Dim Cell As Range
Dim Length As Double
If TypeName(Selection) <> "Range" Then Exit Sub
Application.ScreenUpdating = False
' Create subsets of original selection to avoid processing empty cells
On Error Resume Next
Set ConstantCells = Selection.SpecialCells(xlConstants)
On Error GoTo 0
' Process the constant cells
If Not ConstantCells Is Nothing Then
For Each Cell In ConstantCells
Select Case Len(Cell.Text)
Case 0
Cell.Interior.Pattern = xlNone
Cell.Value = " "
Case 1
Cell.Interior.Pattern = xlNone
Case 2
Cell.Interior.Pattern = xlNone
Cell.Value = "Two"
Case 3
Cell.Interior.Pattern = xlNone
Cell.Value = "Three"
Case 4
Cell.Interior.Pattern = xlNone
Cell.Value = "Four"
Case Is > 4
Cell.Interior.Color = RGB(255, 0, 255)
Cell.Value = "ERROR"
End Select
Next Cell
End If
End Sub
45). The below code shell is designed to determine how many digits are
present and then perform come "action". I need to write the code for the
"action", now that the rest of this is working.
The desired output would look like : 3:00 PM, 9:00 AM, 7:30 AM, 12:45 AM
In excel, using formulas, this is accomplished using a mega formula
consisting of a lot of if statements, etc. etc. And it invloves inserting
columns in the native data to accept the reformed data. My goal is to simply
select the columns that need to be reformed and then run the code.
Sub ConfigureTimeData()
' Converts text time data to 4 digit time data
Dim ConstantCells As Range
Dim Cell As Range
Dim Length As Double
If TypeName(Selection) <> "Range" Then Exit Sub
Application.ScreenUpdating = False
' Create subsets of original selection to avoid processing empty cells
On Error Resume Next
Set ConstantCells = Selection.SpecialCells(xlConstants)
On Error GoTo 0
' Process the constant cells
If Not ConstantCells Is Nothing Then
For Each Cell In ConstantCells
Select Case Len(Cell.Text)
Case 0
Cell.Interior.Pattern = xlNone
Cell.Value = " "
Case 1
Cell.Interior.Pattern = xlNone
Case 2
Cell.Interior.Pattern = xlNone
Cell.Value = "Two"
Case 3
Cell.Interior.Pattern = xlNone
Cell.Value = "Three"
Case 4
Cell.Interior.Pattern = xlNone
Cell.Value = "Four"
Case Is > 4
Cell.Interior.Color = RGB(255, 0, 255)
Cell.Value = "ERROR"
End Select
Next Cell
End If
End Sub