Link to convert pounds to kgs?

leopardhawk

Well-known Member
Joined
May 31, 2007
Messages
611
Office Version
  1. 2016
Platform
  1. Windows
Hello forum friends, I am wondering if it might be at all possible to have a worksheet with some text that was hyperlinked in such a way that clicking it would convert numerous cells (~45) containing numbers representing pounds to kilograms? Some cells are where the user actually enters data (in pounds) and there are other cells containing formulas that return results in pounds (if that makes a difference). Conversely, there would also be a way to convert them back to pounds.

Just wondering if there are any ideas out there about how this might be accomplished.

Thanks!
 
They'll be doing the equivalent, just in a different language like JavaScript.
Edit:
Or because they are fixed values they might even have hard coded the values in the code
 
Last edited:
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Another option, without VBA
Leopardhawk.xlsm
ABC
1Kgs
211
322
433
544
655
766
877
988
1099
111010
121111
131212
141313
151414
161515
171616
181717
191818
201919
212020
222121
232222
242323
252424
262525
Sheet1
Cell Formulas
RangeFormula
B2:B26B2=IF(C$1="Kgs",A2,CONVERT(A2*1000,"g","lbm"))
Cells with Data Validation
CellAllowCriteria
C1ListKgs, lbm


You could then hide Col A
 
Upvote 0
You could use Conditional Formatting to alternate the view that you require Pounds or Kilograms.
The post shows extra information because I showed both arithmetic and Convert.
The Custom Formatting with the Conditional formatting could be ";;;"

T202006a.xlsm
BCDEFG
1Unit required a
2PoundsKilogramsPounds
320.912
441.814
562.726
6209.0720
71000453.591000
8
9
10Units Type ConvertConvert
112lbm0.907kg0.907kg
124lbm1.814kg1.814kg
1320lbm9.072kg9.072kg
141000lbm453.590kg453.592kg
150.907kg2.000lbm2.000lbm
161.814kg4.000lbm4.000lbm
179.072kg20.000lbm20.000lbm
18453.590kg999.985lbm999.995lbm
8c
Cell Formulas
RangeFormula
D3:D7D3=CONVERT(C3,"lbm","g")/1000
E3:E7E3=CONVERT(D3*1000,"g","lbm")
D11:D18D11=IF(C11="lbm",B11*0.45359,IF(C11="kg",B11*2.2046,""))
E11:E18E11=IF(C11="lbm","kg",IF(C11="kg","lbm",""))
F11:F18F11=IF(C11="lbm",CONVERT(B11,"lbm","g")/1000,IF(C11="kg",CONVERT(B11*1000,"g","lbm"),""))
G11:G18G11=IF(C11="lbm","kg",IF(C11="kg","lbm",""))
B15:B16B15=D11
 
Upvote 0
Very lightly tested, but using Mark's code with a worksheet_FollowHyperlink event rather than a worksheet_change event appears to work with a single hyperlink that's linked to itself.

In this example, I used the ribbon menu>Insert>Links>Hyperlink to link cell A1 to itself, entering "Switch to lbs" in the "Text to display" box and A1 in the cell reference box. Then right-click the worksheet tab, choose View Code and paste in the code below. Clicking the link triggers the code which applies the appropriate multiplier to the values in A2 and down, then changes the "Text to display" to invoke the alternate units multiplier when clicked again. Needs some polishing, like rounding of converted results so if you start with 1 lb > convert to 0.45359237 kg and back again you get 1 rather than 0.9999999... lbs.
VBA Code:
Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
If Target.Range.Count = 1 And Target.Range.Address = "$A$1" Then
        Application.EnableEvents = False

        If Target.Range.Value = "Switch to Kg" Then
            With Range("A2", Cells(Rows.Count, "A").End(xlUp))
                .Value = Application.Evaluate(.Address & "*" & 0.45359237)
            End With
            Target.Range.Value = "Switch to lbs"
            Application.EnableEvents = True
            Exit Sub
        End If
   
        If Target.Range.Value = "Switch to lbs" Then
            With Range("A2", Cells(Rows.Count, "A").End(xlUp))
                .Value = Application.Evaluate(.Address & "*" & 2.20462262)
            End With
            Target.Range.Value = "Switch to Kg"
            Application.EnableEvents = True
            Exit Sub
        End If
        Application.EnableEvents = True
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,517
Messages
6,119,984
Members
448,935
Latest member
ijat

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top