PC Review


Reply
Thread Tools Rate Thread

Command button calculation from Userform and Cell reference

 
 
=?Utf-8?B?U0RI?=
Guest
Posts: n/a
 
      17th Apr 2007
I have a userform that has a 'Product' listbox and a 'Quantity' textbox. The
cost of the 'Product' is on a product worksheet. I have a command button on
the Userform called 'Cost'. When clicked i need this button to calculate the
cost of the purchase i.e. purchase price = 'quantity' in text box multiplied
by cost of product. I would like it to be displayed either in a userform or a
message box with an ok button.
 
Reply With Quote
 
 
 
 
Corey
Guest
Posts: n/a
 
      17th Apr 2007
something like:

Private Sub CommandButton1_Click()
If ListBox1.Value <> "" And TextBox1.Value <> "" Then
MsgBox "Total Purchase price is " & ListBox1.Value * TextBox1.Value
End If
End Sub


Where Listbox1 = Product
and
Textbox1 = Quanity


Corey....
"SDH" <(E-Mail Removed)> wrote in message
news:507220EF-81A7-4CD5-A320-(E-Mail Removed)...
I have a userform that has a 'Product' listbox and a 'Quantity' textbox. The
cost of the 'Product' is on a product worksheet. I have a command button on
the Userform called 'Cost'. When clicked i need this button to calculate the
cost of the purchase i.e. purchase price = 'quantity' in text box multiplied
by cost of product. I would like it to be displayed either in a userform or a
message box with an ok button.


 
Reply With Quote
 
=?Utf-8?B?U0RI?=
Guest
Posts: n/a
 
      17th Apr 2007
Very similar Corey, except that the Product ListBox1 is the name of the
product and refers to a cell in column A of the worksheet, where the price of
the product selected is in column B and is the required reference to multiply
against the Quantity entered in TextBox1

"Corey" wrote:

> something like:
>
> Private Sub CommandButton1_Click()
> If ListBox1.Value <> "" And TextBox1.Value <> "" Then
> MsgBox "Total Purchase price is " & ListBox1.Value * TextBox1.Value
> End If
> End Sub
>
>
> Where Listbox1 = Product
> and
> Textbox1 = Quanity
>
>
> Corey....
> "SDH" <(E-Mail Removed)> wrote in message
> news:507220EF-81A7-4CD5-A320-(E-Mail Removed)...
> I have a userform that has a 'Product' listbox and a 'Quantity' textbox. The
> cost of the 'Product' is on a product worksheet. I have a command button on
> the Userform called 'Cost'. When clicked i need this button to calculate the
> cost of the purchase i.e. purchase price = 'quantity' in text box multiplied
> by cost of product. I would like it to be displayed either in a userform or a
> message box with an ok button.
>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      17th Apr 2007

iPos = 0
On Error Resume Next
iPos = Application.Match(lstProducts.Value,
Worksheets("Data").Columns(1),0)
On Error Goto 0
If iPos > 0 Then
MsgBox "Total Purchase price is " &
Worksheets("Data").Cells(iPos,2).Value,* txtQty.Value
End If


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"SDH" <(E-Mail Removed)> wrote in message
news:15FBF2E8-7929-414A-8148-(E-Mail Removed)...
> Very similar Corey, except that the Product ListBox1 is the name of the
> product and refers to a cell in column A of the worksheet, where the price
> of
> the product selected is in column B and is the required reference to
> multiply
> against the Quantity entered in TextBox1
>
> "Corey" wrote:
>
>> something like:
>>
>> Private Sub CommandButton1_Click()
>> If ListBox1.Value <> "" And TextBox1.Value <> "" Then
>> MsgBox "Total Purchase price is " & ListBox1.Value * TextBox1.Value
>> End If
>> End Sub
>>
>>
>> Where Listbox1 = Product
>> and
>> Textbox1 = Quanity
>>
>>
>> Corey....
>> "SDH" <(E-Mail Removed)> wrote in message
>> news:507220EF-81A7-4CD5-A320-(E-Mail Removed)...
>> I have a userform that has a 'Product' listbox and a 'Quantity' textbox.
>> The
>> cost of the 'Product' is on a product worksheet. I have a command button
>> on
>> the Userform called 'Cost'. When clicked i need this button to calculate
>> the
>> cost of the purchase i.e. purchase price = 'quantity' in text box
>> multiplied
>> by cost of product. I would like it to be displayed either in a userform
>> or a
>> message box with an ok button.
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?U0RI?=
Guest
Posts: n/a
 
      18th Apr 2007
thanks Bob, but it is still not working. i have enough knowledge to be
dangerous as they say. i get a syntax error on the MsgBox line at the *.

"Bob Phillips" wrote:

>
> iPos = 0
> On Error Resume Next
> iPos = Application.Match(lstProducts.Value,
> Worksheets("Data").Columns(1),0)
> On Error Goto 0
> If iPos > 0 Then
> MsgBox "Total Purchase price is " &
> Worksheets("Data").Cells(iPos,2).Value,* txtQty.Value
> End If
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "SDH" <(E-Mail Removed)> wrote in message
> news:15FBF2E8-7929-414A-8148-(E-Mail Removed)...
> > Very similar Corey, except that the Product ListBox1 is the name of the
> > product and refers to a cell in column A of the worksheet, where the price
> > of
> > the product selected is in column B and is the required reference to
> > multiply
> > against the Quantity entered in TextBox1
> >
> > "Corey" wrote:
> >
> >> something like:
> >>
> >> Private Sub CommandButton1_Click()
> >> If ListBox1.Value <> "" And TextBox1.Value <> "" Then
> >> MsgBox "Total Purchase price is " & ListBox1.Value * TextBox1.Value
> >> End If
> >> End Sub
> >>
> >>
> >> Where Listbox1 = Product
> >> and
> >> Textbox1 = Quanity
> >>
> >>
> >> Corey....
> >> "SDH" <(E-Mail Removed)> wrote in message
> >> news:507220EF-81A7-4CD5-A320-(E-Mail Removed)...
> >> I have a userform that has a 'Product' listbox and a 'Quantity' textbox.
> >> The
> >> cost of the 'Product' is on a product worksheet. I have a command button
> >> on
> >> the Userform called 'Cost'. When clicked i need this button to calculate
> >> the
> >> cost of the purchase i.e. purchase price = 'quantity' in text box
> >> multiplied
> >> by cost of product. I would like it to be displayed either in a userform
> >> or a
> >> message box with an ok button.
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?U0RI?=
Guest
Posts: n/a
 
      18th Apr 2007
this is the code i have for my lstProducts if that helps.

Private Function UniqueItemList(InputRange As Range, _
HorizontalList As Boolean) As Variant
Dim cl As Range, cUnique As New Collection, i As Long, uList() As Variant
Application.Volatile
On Error Resume Next
For Each cl In InputRange
If cl.Formula <> "" Then
cUnique.Add cl.Value, CStr(cl.Value)
End If
Next cl
UniqueItemList = ""
If cUnique.Count > 0 Then
ReDim uList(1 To cUnique.Count)
For i = 1 To cUnique.Count
uList(i) = cUnique(i)
Next i
UniqueItemList = uList
If Not HorizontalList Then
UniqueItemList = _
Application.WorksheetFunction.Transpose(UniqueItemList)
End If
End If
On Error GoTo 0
End Function

"Bob Phillips" wrote:

>
> iPos = 0
> On Error Resume Next
> iPos = Application.Match(lstProducts.Value,
> Worksheets("Data").Columns(1),0)
> On Error Goto 0
> If iPos > 0 Then
> MsgBox "Total Purchase price is " &
> Worksheets("Data").Cells(iPos,2).Value,* txtQty.Value
> End If
>
>
> --
> HTH
>
> Bob
>
> (there's no email, no snail mail, but somewhere should be gmail in my addy)
>
> "SDH" <(E-Mail Removed)> wrote in message
> news:15FBF2E8-7929-414A-8148-(E-Mail Removed)...
> > Very similar Corey, except that the Product ListBox1 is the name of the
> > product and refers to a cell in column A of the worksheet, where the price
> > of
> > the product selected is in column B and is the required reference to
> > multiply
> > against the Quantity entered in TextBox1
> >
> > "Corey" wrote:
> >
> >> something like:
> >>
> >> Private Sub CommandButton1_Click()
> >> If ListBox1.Value <> "" And TextBox1.Value <> "" Then
> >> MsgBox "Total Purchase price is " & ListBox1.Value * TextBox1.Value
> >> End If
> >> End Sub
> >>
> >>
> >> Where Listbox1 = Product
> >> and
> >> Textbox1 = Quanity
> >>
> >>
> >> Corey....
> >> "SDH" <(E-Mail Removed)> wrote in message
> >> news:507220EF-81A7-4CD5-A320-(E-Mail Removed)...
> >> I have a userform that has a 'Product' listbox and a 'Quantity' textbox.
> >> The
> >> cost of the 'Product' is on a product worksheet. I have a command button
> >> on
> >> the Userform called 'Cost'. When clicked i need this button to calculate
> >> the
> >> cost of the purchase i.e. purchase price = 'quantity' in text box
> >> multiplied
> >> by cost of product. I would like it to be displayed either in a userform
> >> or a
> >> message box with an ok button.
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      18th Apr 2007
I left a stray comma in there, it should be

Worksheets("Data").Cells(iPos,2).Value* txtQty.Value

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"SDH" <(E-Mail Removed)> wrote in message
news:51867EB2-1B6F-4346-A4A6-(E-Mail Removed)...
> thanks Bob, but it is still not working. i have enough knowledge to be
> dangerous as they say. i get a syntax error on the MsgBox line at the *.
>
> "Bob Phillips" wrote:
>
>>
>> iPos = 0
>> On Error Resume Next
>> iPos = Application.Match(lstProducts.Value,
>> Worksheets("Data").Columns(1),0)
>> On Error Goto 0
>> If iPos > 0 Then
>> MsgBox "Total Purchase price is " &
>> Worksheets("Data").Cells(iPos,2).Value,* txtQty.Value
>> End If
>>
>>
>> --
>> HTH
>>
>> Bob
>>
>> (there's no email, no snail mail, but somewhere should be gmail in my
>> addy)
>>
>> "SDH" <(E-Mail Removed)> wrote in message
>> news:15FBF2E8-7929-414A-8148-(E-Mail Removed)...
>> > Very similar Corey, except that the Product ListBox1 is the name of the
>> > product and refers to a cell in column A of the worksheet, where the
>> > price
>> > of
>> > the product selected is in column B and is the required reference to
>> > multiply
>> > against the Quantity entered in TextBox1
>> >
>> > "Corey" wrote:
>> >
>> >> something like:
>> >>
>> >> Private Sub CommandButton1_Click()
>> >> If ListBox1.Value <> "" And TextBox1.Value <> "" Then
>> >> MsgBox "Total Purchase price is " & ListBox1.Value * TextBox1.Value
>> >> End If
>> >> End Sub
>> >>
>> >>
>> >> Where Listbox1 = Product
>> >> and
>> >> Textbox1 = Quanity
>> >>
>> >>
>> >> Corey....
>> >> "SDH" <(E-Mail Removed)> wrote in message
>> >> news:507220EF-81A7-4CD5-A320-(E-Mail Removed)...
>> >> I have a userform that has a 'Product' listbox and a 'Quantity'
>> >> textbox.
>> >> The
>> >> cost of the 'Product' is on a product worksheet. I have a command
>> >> button
>> >> on
>> >> the Userform called 'Cost'. When clicked i need this button to
>> >> calculate
>> >> the
>> >> cost of the purchase i.e. purchase price = 'quantity' in text box
>> >> multiplied
>> >> by cost of product. I would like it to be displayed either in a
>> >> userform
>> >> or a
>> >> message box with an ok button.
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
print command from command button in userform causes double chart Mike Jamesson Microsoft Excel Programming 5 11th Aug 2009 03:42 AM
BUG: print command from command button in userform causes double c Mike Jamesson Microsoft Excel Programming 0 10th Aug 2009 04:19 PM
Userform Command Button not available until another command buttonhas been used MiataDiablo@gmail.com Microsoft Excel Programming 4 4th Sep 2008 04:35 PM
command button, userform Richard Microsoft Frontpage 1 1st Sep 2008 02:20 AM
Change text in a cell from a command button on a Userform Derek Microsoft Excel Programming 2 24th Aug 2008 07:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:45 PM.