Excel VBA, Loop, Copy, Loop, Paste, Autofilter, return value, Loop.

user29383902

New Member
Joined
Dec 6, 2024
Messages
4
Office Version
  1. Prefer Not To Say
Platform
  1. Windows
This doesn't seem to work. I'd appreciate any help out there.


I have One (1) Workbook, Sheet1, then other sheets named "1","2"...."15"sheet1 is where my main data is, while the other sheets contains data i want to filter.


so i want to loop through all rows in sheet1 and filter them individually in the other sheets, while looping, i want to make sure the value in cell "G" in sheet1 matches the other worksheet names.


then paste it, and call a function/sub to autofilter (i already have this figured out).


then return the number of rows returned from the filter to cell "H" of sheet1, that was filtered.


i need all this to be a loop.


Kindly help out.


VBA Code:
Sub DataAnalysis()

    Sub ArrayBuilder() 'Loops through all rows and copy
    
        myarray = Range("A1:M1000")
        
        For i = 1 To UBound(myarray)
        
            For j = 1 To UBound(myarray, 2)
            
            Debug.Print (myarray(i, j))
            
            Next j
        
        Next i
        
        
     
        Dim wkSht As Worksheet
        For Each wkSht In Sheets
                
        X = Range("G1:G1000")
        
            For i = 1 To UBound(myarray)
        
            For j = 1 To UBound(myarray, 2)
            
            Debug.Print (myarray(i, j))
            
            Next j
        
        Next i
                
        If Sheets("Sheet1").Range(X).Value = wkSht.Name Then  'if value of G in rows (that has been looped through)
        'matches the worksheet name, then paste
        
        Sheets("Sheet1").Rows("2:2").Paste
        Application.CutCopyMode = False
        End If
    Next
    
    Application.Run "'FileX.xls'!FilterX"    ' this activates a macro for autofilter and run it, 

    ' I can also paste the code here but that is not the problem right now
    
    
     X1 = Range("H1:H1000")
        
            For i = 1 To UBound(myarray)
        
            For j = 1 To UBound(myarray, 2)
            
            Debug.Print (myarray(i, j))
            
            Next j
        
        Next i
    
    Sheet1.Range(X1).Value = ws.AutoFilter.Range.Columns(1) ' returns the row count on the filtered data to cell H for every loop

End Sub

End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

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