Hi,
I am using blow code in vba, but when two excel files are opened "Subscript out of range" error occur. But when i close the other excel file its working fine.
Private Sub PROJECTNO()
Dim a As Object
Dim rr As Range, r As Range
Dim s As String
Set a = CreateObject("system.collections.arraylist")
Set rr = Worksheets("Boiler Data").Range("B3:B1000").SpecialCells(xlCellTypeVisible)
On Error Resume Next
If Not rr Is Nothing Then
For Each r In rr
s = CStr(r.value)
If Not a.contains(s) Then
a.Add s
End If
Next
a.Sort
ComboBox1.List = a.toarray
End If
End Sub
Please help me to remove this error.
Regards,
Khawaja M. Shakaib
I am using blow code in vba, but when two excel files are opened "Subscript out of range" error occur. But when i close the other excel file its working fine.
Private Sub PROJECTNO()
Dim a As Object
Dim rr As Range, r As Range
Dim s As String
Set a = CreateObject("system.collections.arraylist")
Set rr = Worksheets("Boiler Data").Range("B3:B1000").SpecialCells(xlCellTypeVisible)
On Error Resume Next
If Not rr Is Nothing Then
For Each r In rr
s = CStr(r.value)
If Not a.contains(s) Then
a.Add s
End If
Next
a.Sort
ComboBox1.List = a.toarray
End If
End Sub
Please help me to remove this error.
Regards,
Khawaja M. Shakaib