abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,430
- Office Version
- 2019
- 2010
- Platform
- Windows
hello
i have a problem about this error subscript out of range when run userform and highlights in this line in module
I'm pretty sure about name of userform and this is the whole codes
I hope anybody help
thanks
i have a problem about this error subscript out of range when run userform and highlights in this line in module
VBA Code:
userform2.show
Code:
Private Sub Commandbutton1_Click()
Dim cNum As Integer
Dim X As Integer
Dim nextrow As Range
Dim sht As String
sht = ComboBox1.Value
If Me.ComboBox1.Value = "" Then
MsgBox "Select a sheet from the combobox and add the date"
Exit Sub
End If
cNum = 4
Set nextrow = Sheets(sht).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
For X = 1 To cNum
nextrow = Me.Controls("Reg" & X).Value
Set nextrow = nextrow.Offset(0, 1)
Next
For X = 1 To cNum
Me.Controls("Reg" & X).Value = ""
Next
MsgBox "The values have been sent to the " & sht & " sheet"
End Sub
Private Sub UserForm_Initialize()
Dim s As Long
For s = 1 To Sheets.Count
ComboBox1.AddItem Sheets(s).Name
Next
Dim ws As Worksheet, a, i As Long, j As Long
ListBox1.ColumnWidths = "100;85;85;80;50"
ListBox1.ColumnCount = 4
Z = 1
For j = 1 To 4
inarr = Sheets("SH" & Format(j, "00")).Range("A3:l" & [a65536].End(3).Row).Value
With ListBox1
For i = 1 To UBound(inarr)
.AddItem
.List(Z, 0) = (inarr(i, 1))
.List(Z, 1) = (inarr(i, 2))
.List(Z, 2) = (inarr(i, 3))
.List(Z, 3) = (inarr(i, 4))
Z = Z + 1
Next i
End With
Next j
End Sub
thanks