[FONT="]I have the below macro created. It cycles through all sheets in a workbook, except for X, Y, and Z. For each sheet it takes the value in cell A1, and filters sheet ABC based on that value. Then it selects the displayed values from columns A through S on sheet ABC, down as far as row 100, and copies it into the current sheet. then it moves on to the next.[/FONT]
[FONT="]It works when there is a definite range specified, e.g. A2:S1000. However, the range in the sheet will vary up to maybe 50,000 rows, but i don't want to set a hard cap on it. Also, setting a limit of 50,000 makes the file huge when the macro is run and the file is saved. I am hoping someone can help me find a function which will return the last active row, so that the range is A2 to S(last active row).[/FONT]
[FONT="]Any help appreciated![/FONT]
[FONT="]
[/FONT]
[FONT="]
[/FONT]
[FONT="]It works when there is a definite range specified, e.g. A2:S1000. However, the range in the sheet will vary up to maybe 50,000 rows, but i don't want to set a hard cap on it. Also, setting a limit of 50,000 makes the file huge when the macro is run and the file is saved. I am hoping someone can help me find a function which will return the last active row, so that the range is A2 to S(last active row).[/FONT]
[FONT="]Any help appreciated![/FONT]
[FONT="]
[/FONT]
[FONT="]
Rich (BB code):
Rich (BB code):
Rich (BB code):
Sub FilterAndPaste()[/FONT]
Rich (BB code):
[FONT="]Dim CCS As Worksheet[/FONT]
[FONT="]For Each CCS In Worksheets[/FONT]
[FONT="]Select Case CCS.Name[/FONT]
[FONT="]Case "X", "Y", "Z"[/FONT]
[FONT="]Case Else[/FONT]
[FONT="]CCS.Select[/FONT]
[FONT="]With Worksheets("ABC")[/FONT]
[FONT="].AutoFilterMode = False[/FONT]
[FONT="]With .Range("A1:AC1")[/FONT]
[FONT="].AutoFilter[/FONT]
[FONT="].AutoFilter Field:=24, Criteria1:=Range("A1").Value[/FONT]
[FONT="]Worksheets("ABC").Range("A2:S1000").SpecialCells(xlCellTypeVisible).Copy _[/FONT]
[FONT="]Destination:=CCS.Range("A17")[/FONT]
[FONT="]End With[/FONT]
[FONT="]End With[/FONT]
[FONT="]End Select[/FONT]
[FONT="]Next CCS[/FONT]
[FONT="]End Sub