R
RCrow
I have an excel spreadsheet that has a dropdown box (i.e. cell F6). The
spreadsheet calls a macro based on the choice made in the dropdown box, takes
the data (cost) in cell G6, passes it for conversion to the macro based on
the choice, and outputs the answer to cell H6 (for row = 1 to 65,536). I'm
pretty new to all this, but here is my attempt so far:
Worksheet code:
Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("F6:F65536")
Set t = Target
If Intersect(t, r) Is Nothing Then Exit Sub
Application.EnableEvents = False
For t = 1 To 65536
Call Conversion(t)
Next t
Application.EnableEvents = True
End Sub
And in the modules folder:
Public Sub Conversion(t)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This Macro does conversions based upon choices made in a drop down box '
' Created February 29,2008 '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Roww = t.Row
If Cells("F", Roww).Value = "" Then
Cells("H", Roww).Value = "0.00"
ElseIf Cells(Roww, "F").Value = "BAG" Then
myVar = Val(InputBox("What is the size of the bag in pounds?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / (myVar * 16)
ElseIf Cells(Roww, "F").Value = "BOTTLE" Then
myVar = Val(InputBox("What is the size of the bottle in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "BOX" Then
myVar = Val(InputBox("What is the size of the box in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "CAN" Then
myVar = Val(InputBox("What is the size of the can in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "GAL" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 128
ElseIf Cells(Roww, "F").Value = "GRAM" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value * 0.03527
ElseIf Cells(Roww, "F").Value = "LB" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 16
ElseIf Cells(Roww, "F").Value = "OZ" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value
ElseIf Cells(Roww, "F").Value = "PINT" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 16
ElseIf Cells(Roww, "F").Value = "PACKET" Then
myVar = Val(InputBox("What is the size of the packet in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "QUART" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 32
ElseIf Cells(Roww, "F").Value = "TON" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 32000
End If
End Sub
As you can see, I cant get the thing to work. Any help on this would be
GREATLY appreciated! I know that there are some geniuses out there that can
figure this easy one out!
Thanks in advance!
spreadsheet calls a macro based on the choice made in the dropdown box, takes
the data (cost) in cell G6, passes it for conversion to the macro based on
the choice, and outputs the answer to cell H6 (for row = 1 to 65,536). I'm
pretty new to all this, but here is my attempt so far:
Worksheet code:
Private Sub Worksheet_Change(ByVal Target As Range)
Set r = Range("F6:F65536")
Set t = Target
If Intersect(t, r) Is Nothing Then Exit Sub
Application.EnableEvents = False
For t = 1 To 65536
Call Conversion(t)
Next t
Application.EnableEvents = True
End Sub
And in the modules folder:
Public Sub Conversion(t)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This Macro does conversions based upon choices made in a drop down box '
' Created February 29,2008 '
' '
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Roww = t.Row
If Cells("F", Roww).Value = "" Then
Cells("H", Roww).Value = "0.00"
ElseIf Cells(Roww, "F").Value = "BAG" Then
myVar = Val(InputBox("What is the size of the bag in pounds?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / (myVar * 16)
ElseIf Cells(Roww, "F").Value = "BOTTLE" Then
myVar = Val(InputBox("What is the size of the bottle in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "BOX" Then
myVar = Val(InputBox("What is the size of the box in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "CAN" Then
myVar = Val(InputBox("What is the size of the can in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "GAL" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 128
ElseIf Cells(Roww, "F").Value = "GRAM" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value * 0.03527
ElseIf Cells(Roww, "F").Value = "LB" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 16
ElseIf Cells(Roww, "F").Value = "OZ" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value
ElseIf Cells(Roww, "F").Value = "PINT" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 16
ElseIf Cells(Roww, "F").Value = "PACKET" Then
myVar = Val(InputBox("What is the size of the packet in ounces?"))
Cells(Roww, "H").Value = Cells(Roww, "G").Value / myVar
ElseIf Cells(Roww, "F").Value = "QUART" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 32
ElseIf Cells(Roww, "F").Value = "TON" Then
Cells(Roww, "H").Value = Cells(Roww, "G").Value / 32000
End If
End Sub
As you can see, I cant get the thing to work. Any help on this would be
GREATLY appreciated! I know that there are some geniuses out there that can
figure this easy one out!
Thanks in advance!