i am trying to populate VBA userform listbox with below code. It works if i select range from A to F column. however if i change A to L, it gives me an error.
can you help me to correct below code?
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("part bump")
Dim Last_Row As Long
Dim r, c As Range
Last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
With UserForm3
.lstDatabase.ColumnCount = 11
.lstDatabase.ColumnHeads = True
.lstDatabase.ColumnWidths = "20,40,40,40,2,60,60,60,60,300,60"
Set r = sh.Range("A4:F" & Last_Row)
i = 0
For Each d In r.Rows
j = 0
For Each c In d.Cells
UserForm3.lstDatabase.AddItem
UserForm3.lstDatabase.List(i, j) = c.Value
j = j + 1
Next c
i = i + 1
Next d
If Last_Row = 1 Then
UserForm3.lstDatabase.RowSource = "part bump!A4:F4"
End If
End With
Below code use to update multiple selected rows under userform. it only updates 1st selected row not all selected rows.
Private Sub cmdaction_Click()
Dim t, t1 As String
Dim vrech As Range, lColumn As Range
Dim sh As Worksheet
Dim i As Long
Dim selItem As String
Set sh = ThisWorkbook.Sheets("part bump")
Set lColumn = sh.Range("H1:AZA1").Find(Val(txtchangenumber.Value), , xlValues, xlWhole)
If lColumn Is Nothing Then
MsgBox "Column not found"
Exit Sub
End If
With UserForm3.lstDatabase
For i = 0 To UserForm3.lstDatabase.ListCount - 1
If UserForm3.lstDatabase.Selected(i) = True Then
Set vrech = sh.Range("E3:E250").Find(.Column(4, i), , xlValues, xlWhole)
If Not vrech Is Nothing Then
Select Case cmbaction.Value
Case "RP"
t = Chr(Asc(Mid(.List(i, 4), 2, 1)) + 1)
'Me.lstDatabase.Row (0), Column(4) = "ABA"
t1 = Mid(.List(i, 4), 1, 1) & t & Mid(.List(i, 4), 3, 1)
Intersect(vrech.EntireRow, lColumn.EntireColumn) = t1
Case "RV"
Intersect(vrech.EntireRow, lColumn.EntireColumn) = .List(i, 4)
Case "DP"
Intersect(vrech.EntireRow, lColumn.EntireColumn) = "Deleted"
vrech.EntireRow.Font.Strikethrough = True
End Select
End If
End If
Next i
End With
End Sub