Hi Guys,
I have a weight on 2 different sheets. One sheet reports it in KG the other reports it in LBS
With my limited knowledge of VBA I have tried writing the following code:
There are 2 problems
1. My first IF formula does not work
2. Even if the first IF formula worked, the second IF formula wouldn't because it could have any number of decimal places. Thus not finding a perfect match in O2 (which has 2 decimal places). Even if I bring them down to have the same amount of decimals, it still might not match, so it's just easier to round up or down.
Can I find an exact match by rounding up or down? If so, how do I write that in?
I have a weight on 2 different sheets. One sheet reports it in KG the other reports it in LBS
With my limited knowledge of VBA I have tried writing the following code:
Code:
[COLOR=#008000]'returns weight measurement with 2 decimals - [B]WORKS[/B][/COLOR]
sheet2.Range("Z2").Formula = _
"=VLOOKUP(U2,'DG by Flt Totals'!$A$2:$BA$" & sheet1.Cells(Rows.Count, 1).End(xlUp).row & ",53,0)"
sheet2.Range("Z2:Z" & sheet2.Cells(Rows.Count, 1).End(xlUp).row).FillDown
[COLOR=#008000]'returns measurement standard (i.e. KG or Liters) - [B]WORKS[/B][/COLOR]
sheet2.Range("AA2").Formula = _
"=VLOOKUP(U2,'DG by Flt Totals'!$A$2:$BB$" & sheet1.Cells(Rows.Count, 1).End(xlUp).row & ",54,0)"
sheet2.Range("AA2:AA" & sheet2.Cells(Rows.Count, 1).End(xlUp).row).FillDown
[COLOR=#008000]'IF formula asking IF Z2 = "KG" then multiply weight (Z2) by 2.204...., if not then ""(blank) - [B]DOES NOT WORK[/B][/COLOR]
sheet2.Range("Z2").Formula = [COLOR=#ff0000]"=IF(AA2=""KG"",sum(Z2*2.204),"")"[/COLOR] [COLOR=#008000]' <----- [B]DOES NOT WORK[/B][/COLOR]
sheet2.Range("Z2:Z" & sheet2.Cells(Rows.Count, 1).End(xlUp).row).FillDown
[COLOR=#008000]'IF formula asking IF the weight in AB matches the weight in O2[/COLOR]
sheet2.Range("AB2").Formula = "=IF(AB2=O2,TRUE, FALSE)" [COLOR=#008000]'<--- [B]WILL ALWAYS RETURN FALSE[/B][/COLOR]
sheet2.Range("AB2:AB" & sheet2.Cells(Rows.Count, 1).End(xlUp).row).FillDown
There are 2 problems
1. My first IF formula does not work
2. Even if the first IF formula worked, the second IF formula wouldn't because it could have any number of decimal places. Thus not finding a perfect match in O2 (which has 2 decimal places). Even if I bring them down to have the same amount of decimals, it still might not match, so it's just easier to round up or down.
Can I find an exact match by rounding up or down? If so, how do I write that in?