Editing rows in listbox works for one listbox but not the other

bbowles2

New Member
Joined
Jan 28, 2015
Messages
3
I have a form with two different listboxes. One for downtime data and one for production data. I can add new data and delete data via both listboxes. I can edit a selected row as well. The problem I'm running into is that after I edit and update a row for the production listbox and then enter in new data for new row it keeps putting that data in the last row I edited. If I don't edit a row then anytime I add new data it automatically goes to the next row. This doesn't happen with the downtime section. only the production section. With the downtime section everything works as it should. Attached is the workbook. Any help is greatly appreciated.

This is the code for updating the spreadsheet and the list box
VBA Code:
Sub Prod_Submit()
Dim sh As Worksheet
    Dim iRow As Long
    
    Set sh = ThisWorkbook.Sheets("ADHData")
    
    If MainForm.txtRowNumberProd.Value = "" Then
    
        iRow = [Counta(ADHData!A:A)] + 1
    Else
    
        iRow = MainForm.txtRowNumberProd.Value
        
    End If
    
    
    With sh
    
        
        
        .Cells(iRow, 1) = MainForm.OrderA.Value
        
        .Cells(iRow, 2) = MainForm.StockA.Value
        
        .Cells(iRow, 3) = MainForm.FaceA.Value
        
        .Cells(iRow, 4) = MainForm.LinerA.Value
        
        .Cells(iRow, 5) = MainForm.WidthA.Value
        
        .Cells(iRow, 6) = MainForm.PrevContA.Value
        
        .Cells(iRow, 7) = MainForm.ContA.Value
        
        .Cells(iRow, 8) = MainForm.PrevGoodA.Value
        
        .Cells(iRow, 9) = MainForm.GoodA.Value
        
  
        
    
    End With
End Sub

Sub Prod_Reset()

    Dim iRow As Long
    
    iRow = [Counta(ADHData!A:A)] + 1 
    
    With MainForm
    
        MainForm.OrderA.Value = ""
        
        MainForm.StockA.Value = ""
        
        MainForm.FaceA.Value = ""
        
        MainForm.LinerA.Value = ""
        
        MainForm.WidthA.Value = ""
        
        MainForm.PrevContA.Value = ""
        
        MainForm.ContA.Value = ""
        
        MainForm.PrevGoodA.Value = ""
        
         MainForm.GoodA.Value = ""
        
      
        .Production_TableA.ColumnCount = 9
        .Production_TableA.ColumnHeads = True
        
        .Production_TableA.ColumnWidths = "55,55,70,71,50,106,77,69,42"
        
        If iRow > 1 Then
        
            .Production_TableA.RowSource = "ADHData!A2:J" & iRow
        Else
        
            .Production_TableA.RowSource = "ADHData!A2:J21"
            
        End If
        
        
    
    End With
End Sub


My code that allows me to select the row to edit

VBA Code:
Private Sub CommandButton2_Click()
If Select_Prod = 0 Then
    
        MsgBox "No row is selected.", vbOKOnly + vbInformation, "Edit"
        
        Exit Sub
    
    End If
    
    
    MainForm.txtRowNumberProd.Value = Select_Prod + 1
        
    MainForm.OrderA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 0)
    
    MainForm.StockA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 1)
    
    MainForm.FaceA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 2)
    
    MainForm.LinerA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 3)
    
    MainForm.WidthA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 4)
    
    MainForm.PrevContA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 5)
    
    MainForm.ContA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 6)
    
    MainForm.PrevGoodA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 7)
    
    MainForm.GoodA.Value = MainForm.Production_TableA.List(MainForm.Production_TableA.ListIndex, 8)
    
    MsgBox "Please make the required changes and update the new production data.", vbOKOnly + vbInformation, "Edit"
    
    
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
A reminder:

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,638
Members
449,093
Latest member
Ahmad123098

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