Subscript out of range (vba error) when two (2) excel files opened

shakaib26

New Member
Joined
Feb 3, 2023
Messages
23
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Subscript out of range (vba error) when two (2) excel files opened
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Subscript out of range (vba error) when two (2) excel files opened
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
What kind of link?
 
Upvote 0
A link to any other sites where you have asked this question.
 
Upvote 0

Forum statistics

Threads
1,225,203
Messages
6,183,555
Members
453,168
Latest member
Luggsy

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
Back
Top