Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6625173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:44:31+00:00 2026-05-25T21:44:31+00:00

I have below macro,getting script out of range error in If arr(0) <> opt

  • 0

I have below macro,getting script out of range error in If arr(0) <> opt Then arr(0) = VAL_DIFF

if i see the length of that array it is showing 2.I dont understand why i am not able to access arr(0),As per i know Array always starts with 0.I able to print arr(1),arr(2) values.

Below macro able to findout similar records and copied to sheet2.Here i also wants to highlight with color in sheet1. Please help me.

Option Base 1
Sub Tester()

    Const COL_ID As Integer = 1
    Const COL_SYSID As Integer = 2
    Const COL_STATUS As Integer = 4
    Const COL_OPTION As Integer = 3
    Const VAL_DIFF As String = "XXdifferentXX"

    Dim d As Object, sKey As String, id As String
    Dim rw As Range, opt As String, rngData As Range
    Dim rngCopy As Range, goodId As Boolean
    Dim FirstPass As Boolean, arr

        With Sheet1.Range("A1")
            Set rngData = .CurrentRegion.Offset(1).Resize( _
                             .CurrentRegion.Rows.Count - 1)
        End With
        Set rngCopy = Sheet1.Range("F2")

        Set d = CreateObject("scripting.dictionary")
        FirstPass = True

    redo:
        For Each rw In rngData.Rows

            sKey = rw.Cells(COL_SYSID).Value & "<>" & _
                   rw.Cells(COL_STATUS).Value

            If FirstPass Then
              'Figure out which combinations have different option values
              '  and at least one record with id=US or CHN
              id = rw.Cells(COL_ID).Value
              goodId = (id = "US" Or id = "CHN")
              opt = rw.Cells(COL_OPTION).Value

              If d.exists(sKey) Then
                  arr = d(sKey) 'can't modify the array in situ...
                  If arr(1) <> opt Then arr(1) = VAL_DIFF
                  If goodId Then arr(2) = True
                  d(sKey) = arr 'return [modified] array
              Else
                  d.Add sKey, Array(opt, goodId)
              End If

            Else
              'Second pass - copy only rows with varying options
              '  and id=US or CHN
              If d(sKey)(2) = VAL_DIFF And d(sKey)(1) = True Then
                  rw.Copy rngCopy
                  Set rngCopy = rngCopy.Offset(1, 0)
              End If
            End If

        Next rw
        If FirstPass Then
            FirstPass = False
            GoTo redo
        End If

    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:44:31+00:00Added an answer on May 25, 2026 at 9:44 pm

    Stop using Option Base 1 at the top of your modules. It might seem to make things easier, but it only ends up causing confusion. I already gave you the answer to coloring the range – please try to look things up and try them out before posting here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple macro (simplified version below). At the moment it assumes that
I have below a working query that needs to be simplified. The reason is
I have seen below macro in many topmost header files: #define NULL 0 //
I have a Word macro that needs to run using Java. So I use
I have 2 macros below that I am trying to execute 1 after another
I have the macro below, everything I read states it should work, but when
I have a macro that imports images from a directory and places them in
I have the below vba macro to Export the selected cells into a text
below is a macro I've been working on that updates a set of values
I'm a newbie in boost.python and i'm getting this error that I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.