Calculate Your Weight on Other Planets using Excel

Submitted by: 
Language: 
Visitors have accessed this post 1246 times.

Microsoft Excel spreadsheet with a user defined function in VBA to calculate you weight in kilograms, Lbs, and stone on the 8 planets
MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE.

This Microsoft Excel spreadsheet contains a new function called
YourWeightOnPlanet(p, w).

p = planet name as a string.
w = your weight in Kilogrammes
Use the function like this:
=YourWeightOnPlanet(C9, G$6)
or
=YourWeightOnPlanet("Neptune", 63.6)
to convert Kgs into Lbs example
Lbs = Kgs/454*1000

You must set your security level to low to allow the VBA code to run.

The Excel VBA code looks like this

  1. Public Type PlanetType
  2. Name As String
  3. Mass As Double
  4. Radius As Double
  5. End Type
  6. ' Mass, Radius
  7. ' VENUS (4.869e+24, 6.0518e6),
  8. ' EARTH (5.976e+24, 6.37814e6),
  9. ' MARS (6.421e+23, 3.3972e6),
  10. ' JUPITER (1.9e+27, 7.1492e7),
  11. ' SATURN (5.688e+26, 6.0268e7),
  12. ' URANUS (8.686e+25, 2.5559e7),
  13. ' NEPTUNE (1.024e+26, 2.4746e7);
  14. Public planet(8) As PlanetType
  15.  
  16.  
  17.  
  18. ' Universal gravitational constant (m3 kg-1 s-2)
  19. Const G = 0.00000000006673
  20.  
  21. 'PlanetNum receives the name of one of the 8 planets
  22. 'Returns the planet number 0 to 7
  23. 'else returns -1 to indicate not found
  24.  
  25. Public Function PlanetNum(p As String) As Integer
  26. Dim found As Boolean
  27. Dim i As Integer
  28. Dim PName As String
  29. Dim p1 As String
  30.  
  31. found = False
  32. p1 = Trim(UCase(p))
  33.  
  34. For i = 0 To 7
  35.  
  36. PName = UCase(planet(i).Name)
  37. If p1 = PName Then
  38. found = True
  39. Exit For
  40. End If
  41. Next i
  42.  
  43. If found = False Then
  44. i = -1
  45. End If
  46. PlanetNum = i
  47.  
  48. End Function
  49. 'G * mass / (radius * radius) = surface gravity
  50. 'Given a planet Name return the surface gravity
  51. Public Function SurfaceGravity(planetStr As String) As Double
  52. Dim i As Integer
  53. Dim sg As Double
  54. i = PlanetNum(planetStr)
  55. If i >= 0 Then
  56.  
  57. sg = G * planet(i).Mass / planet(i).Radius ^ 2
  58. 'sg = planet(i).Mass
  59. Else
  60. sg = -1 'error
  61. End If
  62.  
  63. SurfaceGravity = sg
  64.  
  65. End Function
  66.  
  67. 'given a planet name and your mass
  68. 'return your surface weight
  69. Public Function SurfaceWeight(planet As String, yourMass As Double) As Double
  70. Dim i As Integer
  71. Dim sw As Double
  72. i = PlanetNum(planet)
  73. If i >= 0 Then
  74. sw = yourMass * SurfaceGravity(planet)
  75. Else
  76. sw = -1 'error
  77. End If
  78. SurfaceWeight = sw
  79. End Function
  80.  
  81.  
  82. 'Given a planet name and your weight on earth in Kilo grams
  83. 'return your surface weight on the other planet
  84. Function YourWeightOnPlanet(planet As String, yourWeightOnEarth As Double) As Double
  85. Dim yourMass As Double
  86. Dim yourOtherWeight As Double
  87.  
  88. yourMass = yourWeightOnEarth / SurfaceGravity("Earth")
  89. yourOtherWeight = SurfaceWeight(planet, yourMass)
  90.  
  91. YourWeightOnPlanet = yourOtherWeight
  92. End Function

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.