VBA Replace Cell Value Function

Makpo

New Member
Joined
Sep 23, 2011
Messages
28
Hi,

This is like a puzzle for me. I am trying to replace a value in a cell with an update which will add up the old value to the new value. The cell in question is determined by a VLookUp so we cant tell what it will be. Everything else looks fine except this replacement.

This how far I have gone. Can anyone please help with this.

Code:
Private Sub cmdAdd_Click()

Dim ustock As Integer, pstock As Integer
Dim cboPro As Variant

With Worksheets("Sheet5").Range("TS")
pstock = Application.WorksheetFunction.VLookup(Me.cboPro.Value, Worksheets("Sheet5").Range("TS"), 2, False)
End With

ustock = pstock + Val(txtsto)

'I need to replace the value of pstock on my table with an updated stock value ustock which is an addition of the value from a textbox on this userform

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> cmdAdd_Click()<br>    <br>    <SPAN style="color:#00007F">Dim</SPAN> Stock  <SPAN style="color:#00007F">As</SPAN> Range<br><br>    <SPAN style="color:#00007F">With</SPAN> Worksheets("Sheet5").Range("TS")<br>        <SPAN style="color:#00007F">Set</SPAN> Stock = .Find(What:=Me.cboPro.Value, _<br>                          LookIn:=xlValues, _<br>                          LookAt:=xlWhole, _<br>                          SearchOrder:=xlByRows, _<br>                          SearchDirection:=xlNext, _<br>                          MatchCase:=False)<br><br>        <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> Stock <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>            Stock.Offset(, 1).Value = Stock.Offset(, 1).Value + Val(txtsto)<br>        <SPAN style="color:#00007F">Else</SPAN><br>            MsgBox "No match found for " & Me.cboPro.Value<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top