seattletimebandit
Board Regular
- Joined
- Apr 11, 2013
- Messages
- 69
I have a spreadsheet with numbers as text values in cells:
0.5 U
0.500 U
6.06
141 J
... and so on.
I have an issue that some of the number formats have lost (or never had) trailing zeros. The value "0.5 U" should be "0.500 U". So I need to change the number format even though it's not really a number.
I could do a function to change the format, but I have differing formats. In another spreadsheet I had the following macro that could change the number format in a column based on the cell value in an adjacent cell ("U", or "D", or ""). But following code works with actual number values, not text values. Plus i have code that can make format changes to a range instead of having to run the code on specific cols/rows as the following code does.
Note that number formats:
<=1 are "0.000"
>= 1 and <= 9.9 are "0.00"
>= 10 and < 100 are "0.0"
>100 have no decimal point.
The table after the code is an example of formats already in table and those that need to be changed (mostly in Column G).
[TABLE="width: 675"]
<tbody>[TR]
[TD="class: xl65, width: 203, align: center"]Col A[/TD]
[TD="class: xl65, width: 109, align: center"]Col B[/TD]
[TD="class: xl65, width: 71, align: center"]Col C[/TD]
[TD="class: xl65, width: 71, align: center"]Col D[/TD]
[TD="class: xl65, width: 71, align: center"]Col E[/TD]
[TD="class: xl65, width: 71, align: center"]Col F[/TD]
[TD="class: xl65, width: 79, align: center"]Col G[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 675"]
<tbody>[TR]
[TD]CONSTIUTENTS[/TD]
[TD]Cleanup Levels[/TD]
[TD]MW-01[/TD]
[TD]MW-02[/TD]
[TD]MW-03[/TD]
[TD="align: center"]MW-04[/TD]
[TD] MW-05[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Dichlorodifluoromethane[/TD]
[TD][/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1 U[/TD]
[/TR]
[TR]
[TD]Chloromethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Vinyl chloride[/TD]
[TD]525[/TD]
[TD]6.06[/TD]
[TD]0.48[/TD]
[TD]141[/TD]
[TD]0.200 U[/TD]
[TD]0.2 U[/TD]
[/TR]
[TR]
[TD]Bromomethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Trichlorofluoromethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Chloroethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]1,1-Dichloroethene[/TD]
[TD]3.2[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]1.8[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Acetone[/TD]
[TD][/TD]
[TD]2.00 U[/TD]
[TD]2.00 U[/TD]
[TD]2.00 U[/TD]
[TD]2.00 U[/TD]
[TD]2 U[/TD]
[/TR]
[TR]
[TD]Methylene chloride[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]trans-1,2-Dichloroethene[/TD]
[TD]32,000[/TD]
[TD]0.55[/TD]
[TD]0.500 U[/TD]
[TD]89.4[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]1,1-Dichloroethane[/TD]
[TD][/TD]
[TD]0.98[/TD]
[TD]0.500 U[/TD]
[TD]5.85[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]2,2-Dichloropropane[/TD]
[TD][/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1 U[/TD]
[/TR]
[TR]
[TD]cis-1,2-Dichloroethene[/TD]
[TD][/TD]
[TD]56.6[/TD]
[TD]88.1[/TD]
[TD]3,170[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
</tbody>[/TABLE]
0.5 U
0.500 U
6.06
141 J
... and so on.
I have an issue that some of the number formats have lost (or never had) trailing zeros. The value "0.5 U" should be "0.500 U". So I need to change the number format even though it's not really a number.
I could do a function to change the format, but I have differing formats. In another spreadsheet I had the following macro that could change the number format in a column based on the cell value in an adjacent cell ("U", or "D", or ""). But following code works with actual number values, not text values. Plus i have code that can make format changes to a range instead of having to run the code on specific cols/rows as the following code does.
Note that number formats:
<=1 are "0.000"
>= 1 and <= 9.9 are "0.00"
>= 10 and < 100 are "0.0"
>100 have no decimal point.
The table after the code is an example of formats already in table and those that need to be changed (mostly in Column G).
Code:
Sub FormatTableColumns()
'***Loop On Rows and Columns***
'
'This will format Columns 8,10,12, etc. based on what is in 9,11,13, etc.
'
'Increment Columns by 2, Rows by 1
'
'NOTE: RUN THIS CODE AFTER AND TRANSPOSING FROM DATA CHECKING TABLE. DO NOT RUN 'Sub FormatDataChecking TABLE UNTIL AFTER TRANSPOSING.
'
'
For col = 8 To 136 Step 2
For rw = 1 To 26
If Cells(rw, col) <= 1 And Cells(rw, col + 1) = "U" Then _
Cells(rw, col).NumberFormat = """< ""#,##0.00 "
If Cells(rw, col) < 1 And Cells(rw, col + 1) = "U" Then _
Cells(rw, col).NumberFormat = """< ""#,##0.00 "
If Cells(rw, col) >= 10 And Cells(rw, col + 1) = "U" Then _
Cells(rw, col).NumberFormat = """< ""#,### "
If Cells(rw, col) >= 1 And Cells(rw, col) <= 9.9 And _
Cells(rw, col + 1) = "U" Then _
Cells(rw, col).NumberFormat = """< ""#,#0.0 "
'Format numbers in Range of even columns that has an empty cell in Range of odd columns
If Cells(rw, col) < 1 And Cells(rw, col + 1) = "" Then _
Cells(rw, col).NumberFormat = "#,##0.00 "
If Cells(rw, col) >= 1 And Cells(rw, col) <= 9.9 And _
Cells(rw, col + 1) = "" Then Cells(rw, col).NumberFormat = "#,#0.0 "
If Cells(rw, col) >= 1 And Cells(rw, col) <= 9.9 And Cells(rw, col + 1) = "D" Then _
Cells(rw, col).NumberFormat = "#,###0.0 "
If Cells(rw, col) >= 10 And Cells(rw, col + 1) = "D" Then _
Cells(rw, col).NumberFormat = "#,### "
If Cells(rw, col) >= 10 And Cells(rw, col + 1) = "" Then _
Cells(rw, col).NumberFormat = "#,### "
Next
Next
End Sub
[TABLE="width: 675"]
<tbody>[TR]
[TD="class: xl65, width: 203, align: center"]Col A[/TD]
[TD="class: xl65, width: 109, align: center"]Col B[/TD]
[TD="class: xl65, width: 71, align: center"]Col C[/TD]
[TD="class: xl65, width: 71, align: center"]Col D[/TD]
[TD="class: xl65, width: 71, align: center"]Col E[/TD]
[TD="class: xl65, width: 71, align: center"]Col F[/TD]
[TD="class: xl65, width: 79, align: center"]Col G[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="width: 675"]
<tbody>[TR]
[TD]CONSTIUTENTS[/TD]
[TD]Cleanup Levels[/TD]
[TD]MW-01[/TD]
[TD]MW-02[/TD]
[TD]MW-03[/TD]
[TD="align: center"]MW-04[/TD]
[TD] MW-05[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Dichlorodifluoromethane[/TD]
[TD][/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1 U[/TD]
[/TR]
[TR]
[TD]Chloromethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Vinyl chloride[/TD]
[TD]525[/TD]
[TD]6.06[/TD]
[TD]0.48[/TD]
[TD]141[/TD]
[TD]0.200 U[/TD]
[TD]0.2 U[/TD]
[/TR]
[TR]
[TD]Bromomethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Trichlorofluoromethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Chloroethane[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]1,1-Dichloroethene[/TD]
[TD]3.2[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]1.8[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]Acetone[/TD]
[TD][/TD]
[TD]2.00 U[/TD]
[TD]2.00 U[/TD]
[TD]2.00 U[/TD]
[TD]2.00 U[/TD]
[TD]2 U[/TD]
[/TR]
[TR]
[TD]Methylene chloride[/TD]
[TD][/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]trans-1,2-Dichloroethene[/TD]
[TD]32,000[/TD]
[TD]0.55[/TD]
[TD]0.500 U[/TD]
[TD]89.4[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]1,1-Dichloroethane[/TD]
[TD][/TD]
[TD]0.98[/TD]
[TD]0.500 U[/TD]
[TD]5.85[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
[TR]
[TD]2,2-Dichloropropane[/TD]
[TD][/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1.00 U[/TD]
[TD]1 U[/TD]
[/TR]
[TR]
[TD]cis-1,2-Dichloroethene[/TD]
[TD][/TD]
[TD]56.6[/TD]
[TD]88.1[/TD]
[TD]3,170[/TD]
[TD]0.500 U[/TD]
[TD]0.5 U[/TD]
[/TR]
</tbody>[/TABLE]