Excel VBA Update/Edit Data

himaruasuka

New Member
Joined
May 26, 2022
Messages
10
Office Version
  1. 2013
Platform
  1. Windows
  2. Mobile
Good Day!
Sir/Madam, I need help. I don't know how to fix this, I'm new to this. Codes is fine but it didn't find the product item. But if I change from".listcolumn(1)" to ".listcolumn(2)" it can edit the data but It is starts to edit the data at the column3(G), its out of the "listobject(table)."

Anyone who can help me? Thanks in Advance!

VBA Code:
Private Sub Edit_Search_Click()
    Dim rFound As Range
    Dim sID As String
    sID = Me.Search_box.Value
    
    With Worksheets("Inventory").ListObjects("Table1").ListColumns(1).DataBodyRange
        Set rFound = .Find(what:=sID, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
    End With
    
    If Not rFound Is Nothing Then
    Worksheets("Inventory").Unprotect "Roshier"
        rFound.Offset(, "E").Value = Me.display_cat.Text
        rFound.Offset(, "F").Value = Me.display_item.Text
        rFound.Offset(, "G").Value = Me.display_cost.Text
        rFound.Offset(, "H").Value = Me.display_bundle.Text
        rFound.Offset(, "J").Value = Me.display_price.Text
        rFound.Offset(, "K").Value = Me.display_remarks.Text
    Else
        MsgBox "Product Item '" & sID & "' not found.", vbExclamation
    
    Worksheets("Inventory").Protect "Roshier"
    End If
End Sub
 

Attachments

  • Capture2.PNG
    Capture2.PNG
    43.6 KB · Views: 20

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi & welcome to MrExcel.
Change the Find to look in listcolumns(2) & use
VBA Code:
    If Not rFound Is Nothing Then
    Worksheets("Inventory").Unprotect "Roshier"
        rFound.Offset(, -1).Value = Me.display_cat.Text
        rFound.Offset(, 0).Value = Me.display_item.Text
        rFound.Offset(, 1).Value = Me.display_cost.Text
        rFound.Offset(, 2).Value = Me.display_bundle.Text
        rFound.Offset(, 3).Value = Me.display_price.Text
        rFound.Offset(, 4).Value = Me.display_remarks.Text
    Else
 
Upvote 0
Solution
Hi & welcome to MrExcel.
Change the Find to look in listcolumns(2) & use
VBA Code:
    If Not rFound Is Nothing Then
    Worksheets("Inventory").Unprotect "Roshier"
        rFound.Offset(, -1).Value = Me.display_cat.Text
        rFound.Offset(, 0).Value = Me.display_item.Text
        rFound.Offset(, 1).Value = Me.display_cost.Text
        rFound.Offset(, 2).Value = Me.display_bundle.Text
        rFound.Offset(, 3).Value = Me.display_price.Text
        rFound.Offset(, 4).Value = Me.display_remarks.Text
    Else
Ommoo!! Finally! its working really fine now! Thank you so much sir fluff!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

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