+ Reply to Thread
Results 1 to 8 of 8

Find and update table cell

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-07-2015
    Location
    Halifax, NS
    MS-Off Ver
    365
    Posts
    100

    Question Find and update table cell

    I have a table of data (tblProducts) that has 27 columns of data. Periodically it will be necessary to update the value of a cell in one specific column (col 7).
    Rather than having users search the table or bother with a userform, I would like them to be able to locate the cell that requires updating from a small area on the dashboard. I have created a data validation list for the products in the database (column 2 on the database sheet (sheet 2). I also created a VLookup to find the current respective value in column 7. (see image below). The macro I have for the submit button is included below but it results in error 13 Type mismatch. I can't find where the error is. Can anyone help?

    Yield.png

    Option Explicit
    
    Sub UpdateYieldPercentage()
    
    'declare the variables
    Dim findvalue As Range
    Dim DataSH As Worksheet
    Dim WorkSH As Worksheet
    Dim Item As String
    Dim Percent As Long
    
    'error handling
    On Error GoTo ErrHandler:
    
    'hold in memory and stop screen flicker
    Application.ScreenUpdating = False
    
    'set variables
    Set DataSH = Sheet2
    Set WorkSH = Sheet1
    Item = WorkSH.Range("P11").Value
    Percent = WorkSH.Range("Q13").Value
    
    'check for values
    If Item = "" Or Percent = "" Then
    MsgBox "Select a product to update"
    Exit Sub
    End If
    
    'find the row to edit - Column D holds the values of a data validation list in cell P11
    Set findvalue = DataSH.Range("D:D"). _
    Find(What:=Item, LookIn:=xlValues, LookAt:=xlWhole)
    'update the value
    findvalue = Item
    findvalue.Offset(0, 6) = Percent ' column 6 is the value that needs to over updated with the value of cell Q13
    MsgBox "Yield % for " & Item & " updated", vbOKOnly, "YIELD % UPDATE"
    
    Item = ""         ' Here I was to clear the cells on the dashboard (Sheet1)
    Percent = ""
    
    Exit Sub
    ErrHandler:
    'show error information in a messagebox
    MsgBox "An Error has Occurred " & vbCrLf & _
    "The error number is: " & Err.Number & vbCrLf & _
    Err.Description & vbCrLf & "Please notify Chef Jamie"
    
    End Sub

  2. #2
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Find and update table cell

    On which line do you get the error ?

  3. #3
    Forum Contributor
    Join Date
    04-07-2015
    Location
    Halifax, NS
    MS-Off Ver
    365
    Posts
    100

    Re: Find and update table cell

    I don't know. It doesn't tell me and doesn't give me the option to go to debug. When I run compile, it shows no error. Is there another way to locate the line?

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Find and update table cell

    To locate the error line put a single quote before On Error Goto ErrHandler
    Try updating with this code.
    'find the row to edit - Column D holds the values of a data validation list in cell P11
    fRow = Application.Match(Item, Sheet2.Columns(4), 0)
    Sheet2.Cells(fRow, 9).Value = Percent
    MsgBox "Yield % for " & Item & " updated", vbOKOnly, "YIELD % UPDATE"
    Last edited by bakerman2; 04-26-2016 at 04:36 PM.

  5. #5
    Forum Contributor
    Join Date
    04-07-2015
    Location
    Halifax, NS
    MS-Off Ver
    365
    Posts
    100

    Re: Find and update table cell

    Thanks. I didn't know that about commenting out the On Error line. Good thing to know. The error occurred at
    'check for values
    If Item = "" Or Percent = "" Then
    MsgBox "Select a product to update"
    Exit Sub
    End If
    Once I removed that, everything worked great except that I get the same error where I want to clear the values from the dashboard using,
    Item = ""         ' Here I was to clear the cells on the dashboard (Sheet1)
    Percent = ""
    How can I accomplish this?

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Find and update table cell

    Sub UpdateYieldPercentage()
    
    'declare the variables
    Dim Item As String, Percent As Long
    
    'error handling
    On Error GoTo ErrHandler:
    
    'hold in memory and stop screen flicker
    Application.ScreenUpdating = False
    
    'set variables
    Item = Sheet1.Range("P11").Value
    Percent = Sheet1.Range("Q13").Value
    
    'check for values
    If Item = vbNullString Or Percent = 0 Then
    MsgBox "Select a product to update"
    Exit Sub
    End If
    
    'find the row to edit - Column D holds the values of a data validation list in cell P11
    fRow = Application.Match(Item, Sheet2.Columns(4), 0)
    Sheet2.Cells(fRow, 9).Value = Percent
    MsgBox "Yield % for " & Item & " updated", vbOKOnly, "YIELD % UPDATE"
    
    Sheet1.Range("P11").Value = vbNullString       ' Here I was to clear the cells on the dashboard (Sheet1)
    Sheet1.Range("Q13").Value = vbNullString
    
    Exit Sub
    ErrHandler:
    'show error information in a messagebox
    MsgBox "An Error has Occurred " & vbCrLf & _
    "The error number is: " & Err.Number & vbCrLf & _
    Err.Description & vbCrLf & "Please notify Chef Jamie"
    Application.ScreenUpdating = True
    End Sub

  7. #7
    Forum Contributor
    Join Date
    04-07-2015
    Location
    Halifax, NS
    MS-Off Ver
    365
    Posts
    100

    Re: Find and update table cell

    Perfect!! Thank you so much for your help.

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,909

    Re: Find and update table cell

    You're welcome and thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Update cell value referred to a pivot table
    By pezalmendra in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 12-09-2015, 06:26 PM
  2. [SOLVED] Find date/day across columns and update selective cell below
    By emina002 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2015, 01:08 PM
  3. if then macro to find word and update another cell in row with an assigned number
    By carolinapos in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2014, 07:12 PM
  4. Help with VBA code to find bottom row in pivot table and fill table cell borders
    By Eric111 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-28-2014, 07:15 PM
  5. Writing new record in a table upon the update of a cell or cell range
    By bpopov007 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-08-2014, 02:20 AM
  6. Update table by name, not by cell reference
    By jwhitwell in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2010, 08:49 PM
  7. Date in cell to update upon Pivot Table refresh
    By chris46521 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-17-2006, 06:02 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1