Results 1 to 4 of 4

Thread: Update Row on another sheet based on Cell Value

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member
    Join Date
    May 2022
    Posts
    2
    Rep Power
    0

    Update Row on another sheet based on Cell Value

    Hello Everyone,

    I have a form on "Ticket Rating" sheet wherein the user enter the number on cell f7. Then I have a button that runs the below macro and it update the row on sheet "Database" where the number matches the Ticket Number in column E, however, it creates new rows if you save the form multiple times instead of updating only the row with matching Ticket Number. Can you tell me what's wrong with my code and how to prevent it from inserting new row when the number already exist in Database sheet? Would really appreciate your help. Thank you
    TestForm_Save.xlsm

    Code:
    Sub Save()
        Dim frm As Worksheet
        Dim database As Worksheet
        Dim dup As Range
        
        Dim iRow As Long
        Dim iSerial As Long
        
        Set frm = ThisWorkbook.Sheets("Ticket Rating")
        Set database = ThisWorkbook.Sheets("Database")
     
      
        If Trim(frm.Range("m1").Value) = "" Then
            iRow = database.Range("e" & Application.Rows.Count).End(xlUp).Row + 1
            
            If iRow = 2 Then
                iSerial = 1
            Else
                iSerial = database.Cells(iRow - 1, 1).Value + 1
            End If
                Else
            iRow = frm.Range("L1").Value
            iSerial = frm.Range("m1").Value
        End If
        
        With database
            .Cells(iRow, 1).Value = iSerial 'ticket
            .Cells(iRow, 5).Value = frm.Range("f7").Value
            .Cells(iRow, 13).Value = frm.Range("n7").Value
            .Cells(iRow, 6).Value = frm.Range("f9").Value
            .Cells(iRow, 18).Value = frm.Range("n9").Value
            .Cells(iRow, 1).Value = frm.Range("N11").Value
            .Cells(iRow, 9).Value = frm.Range("f14").Value
            .Cells(iRow, 11).Value = frm.Range("n14").Value
            .Cells(iRow, 10).Value = frm.Range("h16").Value
            .Cells(iRow, 7).Value = frm.Range("h18").Value
            .Cells(iRow, 14).Value = frm.Range("h21").Value
            .Cells(iRow, 15).Value = frm.Range("h25").Value
            .Cells(iRow, 19).Value = frm.Range("h29").Value
            .Cells(iRow, 20).Value = frm.Range("h35").Value
            .Cells(iRow, 21).Value = frm.Range("h37").Value
        End With
        
        frm.Range("L1").Value = ""
        frm.Range("m1").Value = ""
        
    End Sub

    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.eileenslounge.com/viewtopic.php?f=30&t=40533&p=314837#p314837
    https://www.eileenslounge.com/viewtopic.php?f=21&t=40701&p=314836#p314836
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314621#p314621
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314619#p314619
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314600#p314600
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314599#p314599
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314274#p314274
    https://www.eileenslounge.com/viewtopic.php?f=27&t=40621&p=314229#p314229
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 03-02-2024 at 02:41 PM.

Similar Threads

  1. Replies: 4
    Last Post: 02-27-2014, 08:49 PM
  2. Replies: 30
    Last Post: 07-19-2013, 07:52 AM
  3. Replies: 2
    Last Post: 05-30-2013, 07:28 PM
  4. Replies: 4
    Last Post: 02-22-2013, 02:24 AM
  5. Autofill the data based on non blank cell in next row?
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 3
    Last Post: 11-29-2012, 04:16 PM

Posting Permissions

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