0

I need advise from the pros here. i basically have 0 knowledge on vba excel.

I recently had designed a UserForm and i took advantage of online code.

First of all, i have this UserForm allowing me to key in a part number and search from this sheet call "MASTER" in "pntxt" textbox and it will return a list of values to text box 2 to 10. This part of the code is already working and running well.

To further enhance it, i would like to have the "update" button in this user form.

For example, one of the text box is name as "pricetxt" after calling out using values from "pntxt", as a user, i need to amend the "pricetxt" textbox. after which, it will update back my excel sheet.

I had tried the following code and it's not working.

Private Sub update2_Click()
Dim lastRow As Variant
Dim partno As Variant
Dim rowSelect As Variant
Dim x As Variant


If Trim(pntxt.Value) = vbNullString Then

MsgBox "Enter Part Number"

 Else

partno = pntxt.Value
Sheets("MASTER").Select

Set wS = Worksheets("MASTER")
lastRow = wS.Cells(Rows.count, 2).End(xlUp).Row

For x = 2 To lastRow
If wS.Cells(x, 2).Value = partno Then Rows(x).Select

Next

rowSelect = ActiveCell.Row
Cells(rowSelect, 20) = Me.pricetxt.Value


End If

End Sub

The code above does not returned the "pricetxt" values to the corresponding rows as "pntxt" values.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
  • 3
    There's a lot of room for improvement in the code, but it's impossible to tell what *it's not working* means. Is the routine triggered at all? Do you have issues with Upper/Lower case? My advice is to set a breakpoint at the first statement of your code (F9), see if the execution stops after you enter your search term (else your code is not executed at all) and then step thru the routine (F8) to see how the code is executed and where it fails to do what you want. – FunThomas Apr 01 '19 at 09:42
  • 3
    You might benefit from reading [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). • Also declare your variables properly `Variant` is the worst type you could choose. And I recommend always to activate `Option Explicit`: In the VBA editor go to *Tools* › *Options* › *[Require Variable Declaration](https://www.excel-easy.com/vba/examples/option-explicit.html)*. – Pᴇʜ Apr 01 '19 at 10:02

0 Answers0