ScorchedLemonade
Technical User
I've got the following situation: a list of 3 columns
x1 y1 z1
x2 y2 z2
x3 y3 z3
... ... ...
x10 y10 z10
The x1-x10, y1-y10, z1-z10 are pulled from a larger set of lists via formulae like:
=MIN(INDIRECT("B4:B"&$B$1-4))
=IF(COUNTIF(INDIRECT("B4:B"&$B$1-4),I5)>COUNTIF(I$4:I5,I5),I5,MIN(IF(INDIRECT("B4:B"&$B$1-4)<=I5,10000000,INDIRECT("B4:B"&$B$1-4)))) (xs)
=INDEX($A:$A,MATCH(I5,$B:$B,0)) (ys)
and
=IF(RIGHT(J5,1)="=",1/INDEX(S!$J:$J,MATCH(J5,S!$A:$A,0)),INDEX(S!$J:$J,MATCH(J5,S!$A:$A,0))) (zs)
Anyway, the main point is that the ys are just regular text and the zs are numbers.
They are linked to the xs which are a list of numbers also from a larger list (the bottom 10 of that list) and which are continously liable to change.
I'm wanting the zs to be formatted either as NumberFormat 0.00 or 0.0000 depending on the text in the corresponding ys.
I can conditionally format the zs to change colour if the ys change (and the number format is not appropriate) but not to change the number format itself.
Thus I can define a name NF referring to
=GET.CELL(7,INDIRECT("rc",FALSE))
and then set up conditions like
=and(right(RC[-1],1)="#",NF="0.00")
to turn the cell blue if y ends with # and the number format is 0.00 with other formats if say it doesn't end in # and the number format is 0.0000
Unfortunately, I can't then use the following to correct my number formatting because the changing of the colours doesn't trigger the macro (and because though the values of the xs, ys and zs change depending on the list they link to the actual formula doesn't - so that doesn't fire the macro either).
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng
With Target
Set rng = Application.Intersect(Target, Range("J5:J14"))
If Not rng Is Nothing Then
If Right(Cells(.Row), 1) = "=" Then
Cells(.Row, "K").NumberFormat = "0.0000"
Else
Cells(.Row, "K").NumberFormat = "0.00"
End If
End If
Set rng = Application.Intersect(Target, Range("M5:M14"))
If Not rng Is Nothing Then
If Right(Cells(.Row), 1) = "#" Then
Cells(.Row, "N").NumberFormat = "0.0000"
Else
Cells(.Row, "N").NumberFormat = "0.00"
End If
End If
End With
End Sub
Is it possible to do this sort of thing, preferably in a way that isn't too exhaustive on resources as the file is already pretty intensive as it is?
Thanks.