Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,227
- Office Version
- 2010
- Platform
- Windows
Hi hope you can help i want to combine the 2 vba codes below together if possible as i cant have both on same sheet as i get an error hope you can help?
And
VBA Code:
Private Sub UserForm_Initialize()
cmdUpdate.Enabled = False 'Only enable the button when a row has been returned
'Source for this nifty code is from here:
'http://stackoverflow.com/questions/10763310/how-to-populate-data-from-a-range-multiple-rows-and-columns-to-listbox-with-vb
Dim rng As Range
Dim i As Long, j As Long, rw As Long
Dim Myarray() As String
Set rng = Range("ListBox1")
With Me.ListBox1
.Clear
.ColumnHeads = False
.ColumnCount = rng.Columns.Count
ReDim Myarray(rng.Rows.Count, rng.Columns.Count)
rw = 0
For i = 1 To rng.Rows.Count
For j = 0 To rng.Columns.Count
Myarray(rw, j) = rng.Cells(i, j + 1)
Next
rw = rw + 1
Next
.List = Myarray
'.TopIndex = 1
End With
If Val(Me.txtLBSelectionIndex) > 1 Then
Me.ListBox1.Selected(Val(Me.txtLBSelectionIndex)) = True
End If
End Sub
And
Code:
Private Sub UserForm_Initialize()
ListBox1.ColumnCount = 24
ListBox1.RowSource = "B2:F7"
ListBox1.ColumnHeads = True
End Sub