Barboza Babcock
New Member
- Joined
- Jul 3, 2020
- Messages
- 13
- Office Version
- 365
- Platform
- Windows
Hello All,
I'm losing it. What else is new? The code below has run flawlessly for quite some time. All results generated by our lab are reported to 3 sig figs. The other day the code below suddenly started leaving all values => 1000 unchanged.
If we select a cell => 1000 on the sheet and run ONLY the sig fig macro on the selected cell, the numbers change to sig figs. For example, 5637 is changed to 5640.
If we run CallSelectByValue() macro then SelectByValue() prior to SlectByValue running the SigFig() macro, numbers =>1000 are left unchanged. All the numbers in the specified ranges get selected, however, the numbers do not change when the SigFig() macro runs if the numbers selected are =>1000. Bizarre.
As above, if you just go to a sheet, and select any number and run the SigFig() macro only, the selected number is set to sig figs.
As always, any help is greatly appreciated.
Thanks!!
I'm losing it. What else is new? The code below has run flawlessly for quite some time. All results generated by our lab are reported to 3 sig figs. The other day the code below suddenly started leaving all values => 1000 unchanged.
If we select a cell => 1000 on the sheet and run ONLY the sig fig macro on the selected cell, the numbers change to sig figs. For example, 5637 is changed to 5640.
If we run CallSelectByValue() macro then SelectByValue() prior to SlectByValue running the SigFig() macro, numbers =>1000 are left unchanged. All the numbers in the specified ranges get selected, however, the numbers do not change when the SigFig() macro runs if the numbers selected are =>1000. Bizarre.
As above, if you just go to a sheet, and select any number and run the SigFig() macro only, the selected number is set to sig figs.
VBA Code:
Sub CallSelectByValue()
'Call the macro and pass all the required variables to it.
'In the line below, change the Range, Minimum Value, and Maximum Value as needed
Select Case ActiveSheet.Name
Case Is = "Vol Log"
Set rngSearchFor = Range("B9:PZ69")
rngSearchFor.Select
Case Is = "HAA Log"
Set rngSearchFor = Range("D4:I68")
rngSearchFor.Select
End Select
Call SelectByValue(Range(Selection.Address), 0.00000001, 0.9999999999)
rngSearchFor.Select
Call SelectByValue(Range(Selection.Address), 1, 9.99999999)
rngSearchFor.Select
Call SelectByValue(Range(Selection.Address), 10, 99.99999999)
rngSearchFor.Select
Call SelectByValue(Range(Selection.Address), 100, 999.99999999)
rngSearchFor.Select
Call SelectByValue(Range(Selection.Address), 1000, 9999.99999999)
rngSearchFor.Select
Call SelectByValue(Range(Selection.Address), 10000, 99999.99999999)
rngSearchFor.Select
Call SelectByValue(Range(Selection.Address), 100000, 999999.99999999)
End Sub
Sub SelectByValue(Rng1 As Range, MinimunValue As Double, MaximumValue As Double)
Dim MyRange As Range
Dim Cell As Object
'Check every cell in the range for matching criteria.
For Each Cell In Rng1
If Cell.Value >= MinimunValue And Cell.Value <= MaximumValue Then
If MyRange Is Nothing Then
Set MyRange = Range(Cell.Address)
Else
Set MyRange = Union(MyRange, Range(Cell.Address))
Set MyRange = Union(MyRange, Range(Cell.Address))
End If
End If
Next
'Select the new range of only matching criteria
If MyRange Is Nothing Then
Exit Sub
Else
MyRange.Select
End If
Run ("SigFig")
End Sub
Sub SigFig()
'
' SigFig Macro
' Use function SigDig to put digits into sig figs.
If IsNumeric(ActiveCell) Then
ActiveCell = SigDig(ActiveCell, 3)
Select Case ActiveCell
Case Is < 0.1 And ActiveSheet.Name <> "ICPDATA"
Selection.NumberFormat = "0.0000"
Case Is < 1
Selection.NumberFormat = "0.000"
Case Is < 10
Selection.NumberFormat = "0.00"
Case Is < 100
Selection.NumberFormat = "0.0"
Case Is < 1000
Selection.NumberFormat = "0"
Case Is < 10000
Selection.NumberFormat = "00"
Case Is < 100000
Selection.NumberFormat = "000"
Case Is < 1000000
Selection.NumberFormat = "0000"
End Select
End If
As always, any help is greatly appreciated.
Thanks!!