How can i get the converted value from Celsius to Fahrenheit to show in a cell in the workbook of my choice? Here is The Code for the problem:
Option Explicit
Private Sub UserForm_Initialize()
ComboBox1.AddItem "Inches to Centimeters"
ComboBox1.AddItem "Feet to Meters"
ComboBox1.AddItem "Celsius to Fahrenheit"
' Add more conversion options as needed
End Sub
Private Sub CommandButton1_Click()
Dim inputValue As Double
Dim conversionFactor As Double
Dim convertedValue As Double
Dim targetCell As Range
inputValue = Val(TextBox1.Value)
If IsNumeric(inputValue) Then
Select Case ComboBox1.Value
Case "Inches to Centimeters"
conversionFactor = 2.54
Case "Feet to Meters"
conversionFactor = 0.3048
Case "Celsius to Fahrenheit"
convertedValue = (inputValue * 9 / 5) + 32
MsgBox inputValue & " degrees Celsius converted to Fahrenheit is " & convertedValue
' Add more cases for other conversion options
End Select
convertedValue = inputValue * conversionFactor
' Prompt the user to select a cell to put the converted value
' Code Here
MsgBox "Please enter a valid numeric value."
End If
End Sub
Private Sub CommandButton2_Click()
Dim inputValue As Double
Dim conversionFactor As Double
Dim convertedValue As Double
Dim targetCell As Range
inputValue = Val(TextBox1.Value)
If IsNumeric(inputValue) Then
Select Case ComboBox1.Value
Case "Inches to Centimeters"
conversionFactor = 1 / 2.54
Case "Feet to Meters"
conversionFactor = 1 / 0.3048
Case "Celsius to Fahrenheit"
convertedValue = (inputValue - 32) * 5 / 9
MsgBox inputValue & " degrees Fahrenheit converted to Celsius is " & convertedValue
' Add more cases for other conversion options
End Select
convertedValue = inputValue * conversionFactor
' Prompt the user to select a cell to put the converted value
' Code Here
Else
MsgBox "Please enter a valid numeric value."
End If
End Sub
I want to add a piece of code that us a input box where I can select a cell in the workbook to display the Converted Value. I have placed comment blocks in my code to know where to type the code in.