Excel 2007 subscript out of range error but runs in 365

andymalan

Board Regular
Joined
Feb 22, 2017
Messages
128
Office Version
  1. 365
  2. 2007
Platform
  1. Windows
good evening everyone
the following code run fine in excel 365, but throws up a "subscript out of range error" when run in 2007. what must be changed so that it will run in 2007?
VBA Code:
 '   Check if "Pos" is found in range A1:A14
       Sheets("Cabinets").Select
    Set rng = Range("A1:A14").Find(What:="Pos", After:=Range("A1"), LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
            If rng Is Nothing Then
    MsgBox "Position numbers are not present-- select ""with Position"" from Winner, re-print the element list and convert to Excel", vbOK + vbCritical
    If rng Is Nothing Then
    Application.Quit
    End If
    End If
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
What line of code is highlighted when you hit "Debug"?

I have a feeling it may be this part here:
LookIn:=xlFormulas2

I am not sure that option was available in Excel 2007. Try removing the "2" off the end, and see if that fixes it.
 
Upvote 0
Solution
What line of code is highlighted when you hit "Debug"?

I have a feeling it may be this part here:
LookIn:=xlFormulas2

I am not sure that option was available in Excel 2007. Try removing the "2" off the end, and see if that fixes it.
That fixed it Joe4, thank you ever so much. I am going to post another error, and I will be really happy if you could find the time to have a look?
Kind regards
Andy
 
Upvote 0
You are welcome.

All things equal, if you have access to BOTH versions of Excel, it is usually best to write your VBA code on the oldest version you will be using to run it.
If it works on the older version, there is about a 99% chance it will work on the newer version (granted that you have the same drive mappings, libraries selected, etc).
If you write it on the newer version, there is a much higher chance it won't work on the older version, as you may be using newer functionality that was not available on the older version.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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