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).
<tbody>
</tbody>
<tbody>
</tbody>
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
Col A | Col B | Col C | Col D | Col E | Col F | Col G |
<tbody>
</tbody>
CONSTIUTENTS | Cleanup Levels | MW-01 | MW-02 | MW-03 | MW-04 | MW-05 |
Dichlorodifluoromethane | 1.00 U | 1.00 U | 1.00 U | 1.00 U | 1 U | |
Chloromethane | 0.500 U | 0.500 U | 0.500 U | 0.500 U | 0.5 U | |
Vinyl chloride | 525 | 6.06 | 0.48 | 141 | 0.200 U | 0.2 U |
Bromomethane | 0.500 U | 0.500 U | 0.500 U | 0.500 U | 0.5 U | |
Trichlorofluoromethane | 0.500 U | 0.500 U | 0.500 U | 0.500 U | 0.5 U | |
Chloroethane | 0.500 U | 0.500 U | 0.500 U | 0.500 U | 0.5 U | |
1,1-Dichloroethene | 3.2 | 0.500 U | 0.500 U | 1.8 | 0.500 U | 0.5 U |
Acetone | 2.00 U | 2.00 U | 2.00 U | 2.00 U | 2 U | |
Methylene chloride | 0.500 U | 0.500 U | 0.500 U | 0.500 U | 0.5 U | |
trans-1,2-Dichloroethene | 32,000 | 0.55 | 0.500 U | 89.4 | 0.500 U | 0.5 U |
1,1-Dichloroethane | 0.98 | 0.500 U | 5.85 | 0.500 U | 0.5 U | |
2,2-Dichloropropane | 1.00 U | 1.00 U | 1.00 U | 1.00 U | 1 U | |
cis-1,2-Dichloroethene | 56.6 | 88.1 | 3,170 | 0.500 U | 0.5 U |
<tbody>
</tbody>