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 6947447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:41:39+00:00 2026-05-27T13:41:39+00:00

I’m kinda stuck with this task. I have a macro that retrieve two ranges

  • 0

I’m kinda stuck with this task. I have a macro that retrieve two ranges of data to process from two different workbooks and stuff them into two Variant. The gathering is successful as I can debug and inspect them in Local window, one being data1(variant 1 to 79) and other data2(variant 1 to 10). This is how I get data1

 With wbExterno.Sheets(1)
data1 = .Range(tmpStr + ":" & ToolboxMod.Number2Char(lastCol) & lastRow).Value
End With

Now I want to copy relevant elements from data1 to a new array, name it Dim newData as Variant. I’ve already checked in SO about this and this is what I got

Dim filterCount As Integer
    counter = 0
    filterCount = 1    
' Para cada elemento en el array...
        For i = 1 To UBound(data1)

            'Comparar el campo fecha...
            tmpTest = data1(i, 1)

            ' ...con la fecha del ejercicio
            If (comparacionActual.FechaEjercicio = tmpTest) Then
                'MsgBox "iguales!"

                'se crea un array filtrado con los elementos pertinentes
                filter1(filterCount) = Application.WorksheetFunction.Index(data1, 0, i)

                PlusOne filterCount 'this is a custom function that increments in 1
            End If
        Next

        ' se informa el resultado del filtrado
        MsgBox "Copied: " & filterCount & " rows."

It raises a Error 1004 unable to get Index property from worksheetfunction. What am I doing wrong here? Should I filter the input into data1 instead? Easier that way? Faster?

EDIT: I’ve tried the method in a worksheet with the same data (no VBA) and it only worked with the translated method name ( =Index() in spanish is =Indice() ). Other than that, it worked. But, tried setting data1 as range and variant and… it didn’t work.
Also, I checked with a breakpoint and data1 is a Variant/Variant(78) and each element (data1(i) ) is a Variant (1 To 8) containing each row

EDIT 2: After a test suggested in the answers, I tried a more old-school approach:

With wbInterno.Sheets(1)
    data1 = .Range(tmpStr + ":" & ToolboxMod.Number2Char(lastCol) & lastRow).Value
    filter1 = wbMe.Worksheets.Add.Range(tmpStr + ":" & ToolboxMod.Number2Char(lastCol) & lastRow).Value
End With

'... some other stuff

' Field by field
For j = LBound(data1, 2) To UBound(data1, 2)
    'MsgBox "check" & data1(i, j)
    filter1(filterCount, j) = data1(i, j)
Next

And it actually sets field by field, the rows I need in the new array. I’ll leave the question unanswered; perhaps we can find a better way.

Solution The code I use in the end is this one:

     ' Define array with a range. Initialize destination array with the same size.
     data1 = .Range(tmpStr + ":" & ToolboxMod.Number2Char(lastCol) & lastRow).Value
     filter1 = wbMe.Sheets("tmp").Range(tmpStr + ":" & ToolboxMod.Number2Char(lastCol) & lastRow).Value

… some more code not relevant to this and then

     Dim tmpTest As Variant
        Dim filterCount As Integer
        filterCount = 1
        ' integer used for presentation only 
        conteoRegistros = 0        
' for each element in array...
        For i = 1 To UBound(data1)
            'Compare a certain field...
            tmpTest = data1(i, 1)
            ' ...with some other variable. If so...
            If (comparacionActual.FechaEjercicio = tmpTest) Then
                '...copy column by column into new
                For j = LBound(data1, 2) To UBound(data1, 2)
                    'MsgBox "check" & data1(i, j)
                    filter1(filterCount, j) = data1(i, j)
                Next

                PlusOne filterCount
                PlusOne conteoRegistros
            End If
        Next
  • 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-27T13:41:40+00:00Added an answer on May 27, 2026 at 1:41 pm

    OK, I had time to look at it. If your Index function doesn’t have the correct parameters then it will throw the error 1004. Let’s say if your range is a single cell, then when you look for a value in column 2, it won’t come up with anything (i.e., error 1004). But column 1 row 1 will return a correct result.

    So in your code make sure that the variable i is not being exceeded. So this is what is wrong in your code:

    For i = 1 To UBound(data1)
    

    Should be

    For i = 1 To UBound(data1, 2)
    

    So it wont exceed the number of columns in your array.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to

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.