ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Help with code please (https://www.excelbanter.com/excel-programming/351770-help-code-please.html)

Greg B[_7_]

Help with code please
 
I am looking for help with a macro.

I have a userform where I use combobox1 to select the person I need. I need
the macro to lookup the matching value in combobox1 to the value selected
from column A.
then using code, I wish to add the value of textbox1 to the value of the
cell in column b and have the total of the two be laced in that cell.

for example i have

combobox1 value = greg

textbox1 = 5



column a column b
greg 3


I would like for column b to change to 8


How would I do that?


Thanks Greg



Rick Hansen

Help with code please
 
Hello Greg,
Give this code a shot, and see if it does what your looking for. I run
this example code from a UserForm using a CommandButton1, ComboBox1,
TextBox1. If you have any questions, feel free to ask.

Enjoy, Rick


Option Explicit
Private Sub CommandButton1_Click()
Dim ws1 As Worksheet
Dim r As Integer

Set ws1 = Worksheets("Sheet1")
r = 3 '' start row

'' Find Name in Column "A" Sheet1
Do Until IsEmpty(ws1.Cells(r, "A"))
If Me.ComboBox1 = ws1.Cells(r, "A") Then
ws1.Cells(r, "B") = ws1.Cells(r, "B") + CInt(Me.TextBox1)
Exit Sub '' name found, let exit sub
End If
r = r + 1 '' next row

Loop

End Sub



"Greg B" wrote in message
...
I am looking for help with a macro.

I have a userform where I use combobox1 to select the person I need. I

need
the macro to lookup the matching value in combobox1 to the value selected
from column A.
then using code, I wish to add the value of textbox1 to the value of the
cell in column b and have the total of the two be laced in that cell.

for example i have

combobox1 value = greg

textbox1 = 5



column a column b
greg 3


I would like for column b to change to 8


How would I do that?


Thanks Greg





Bob Phillips[_6_]

Help with code please
 
Is the combobox sourced from Column A? If so, why not use the Listindex
property

With Range("B" & Combobox1.Listindex)
.Value = .Value + CDbl(Textbox1.Text)
End With

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)

"Greg B" wrote in message
...
I am looking for help with a macro.

I have a userform where I use combobox1 to select the person I need. I

need
the macro to lookup the matching value in combobox1 to the value selected
from column A.
then using code, I wish to add the value of textbox1 to the value of the
cell in column b and have the total of the two be laced in that cell.

for example i have

combobox1 value = greg

textbox1 = 5



column a column b
greg 3


I would like for column b to change to 8


How would I do that?


Thanks Greg





Greg B[_7_]

Help with code please
 
Thank you both for the help it works great.

Greg
"Rick Hansen" wrote in message
...
Hello Greg,
Give this code a shot, and see if it does what your looking for. I run
this example code from a UserForm using a CommandButton1, ComboBox1,
TextBox1. If you have any questions, feel free to ask.

Enjoy, Rick


Option Explicit
Private Sub CommandButton1_Click()
Dim ws1 As Worksheet
Dim r As Integer

Set ws1 = Worksheets("Sheet1")
r = 3 '' start row

'' Find Name in Column "A" Sheet1
Do Until IsEmpty(ws1.Cells(r, "A"))
If Me.ComboBox1 = ws1.Cells(r, "A") Then
ws1.Cells(r, "B") = ws1.Cells(r, "B") + CInt(Me.TextBox1)
Exit Sub '' name found, let exit sub
End If
r = r + 1 '' next row

Loop

End Sub



"Greg B" wrote in message
...
I am looking for help with a macro.

I have a userform where I use combobox1 to select the person I need. I

need
the macro to lookup the matching value in combobox1 to the value selected
from column A.
then using code, I wish to add the value of textbox1 to the value of the
cell in column b and have the total of the two be laced in that cell.

for example i have

combobox1 value = greg

textbox1 = 5



column a column b
greg 3


I would like for column b to change to 8


How would I do that?


Thanks Greg








All times are GMT +1. The time now is 03:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com