Can't get listview to update after second form inputs data

j_tyd

New Member
Joined
Apr 15, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi All,

Trying to get listview to populate after the user inputs names into a second form. The firstname and second name are put into excel cells.

When Form 1 initializes the listview populates with this code:
VBA Code:
Private Sub UserForm_Initialize()

   'Set some of the properties for the ListView
    With Me.ListView1
        .Gridlines = True
        .HideColumnHeaders = False
        .View = lvwReport
    End With
   
    'Call the sub to fill the ListView
    Call LoadListView
   
End Sub

Sub LoadListView()

    'Declare the variables
    Dim wksSource As Worksheet 'Dim
    Dim rngData As Range
    Dim rngCell As Range
    Dim LstItem As ListItem
    Dim RowCount As Long
    Dim ColCount As Long
    Dim i As Long
    Dim j As Long
      
    'Clear list
    Me.ListView1.ListItems.Clear
   
    'Set the source worksheet
    Set wksSource = Worksheets("settings")
   
    'Set the source range
    Set rngData = wksSource.Range("A1").CurrentRegion
   
    'Add the column headers
    For Each rngCell In rngData.Rows(1).Cells
        Me.ListView1.ColumnHeaders.Add Text:=rngCell.Value, Width:=90 '# Me.ListView1
    Next rngCell
   
    'Count the number of rows in the source range
    RowCount = rngData.Rows.Count
   
    'Count the number of columns in the source range
    ColCount = rngData.Columns.Count
   
    'Fill the ListView
    For i = 2 To RowCount
        Set LstItem = Me.ListView1.ListItems.Add(Text:=rngData(i, 1).Value) '# Me.ListView1
        For j = 2 To ColCount
            LstItem.ListSubItems.Add Text:=rngData(i, j).Value
        Next j
    Next i
   
End Sub

On Form 2 when button is clicked, data is added to two cells, and trying to run the listview command again on Form 1 comes up with error: Run-time error '424'. Object required.

VBA Code:
Sub CommandButton1_Click()

    NextEmptyRow = Sheets("settings").Cells(Rows.Count, "A").End(xlUp).Offset(1).Row
    Sheets("settings").Cells(NextEmptyRow, "A").Value = TextBox1.Value
    Sheets("settings").Cells(NextEmptyRow, "B").Value = TextBox2.Value
   
    Form_Settings.LoadListView (anyVars)
   
    Unload Me
   
End Sub

Been trying to fix this for a few days but most suggested is to use different Form options e.g. Forms!(formname) etc.. which is not working. Any help appreciated!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

j_tyd

New Member
Joined
Apr 15, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Managed to fix this, problem was with the way I was calling it.

VBA Code:
Call Settings.LoadListView

This is all that was needed!
 
Solution

Forum statistics

Threads
1,181,638
Messages
5,931,154
Members
436,778
Latest member
TCarr1958

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
Top