alexenvalencia
New Member
- Joined
- Mar 25, 2011
- Messages
- 11
My original question:
I have a block of data which I want to select in order to copy it.
It begins in column A and runs to column AU. It begins in row 2 and runs down a number of rows (typically 2000 rows but it varies) until there is no data in the rows.
Column C is the KEY and has data all the way till the last row so we should use this to determine how far down we need to make the selection.
Roberts excellent solution:
</PRE>
A problem remains: The block of data is often autofiltered by the user with the filter being applied to COLUMN C (the key column). I need to copy the ENTIRE block of data to a new sheet, while not removing the user defined autofilter as he doesnt want to lose his filter settings (a valid option is to remove the filter, remember the settings, execute the copy and reapply the filter, but there must surely be a simpler solution).
Robert suggested:
</PRE>
Which is a nice attempt but unfortunately I need to simulate the effects of a plain sourcesheet.copy, destinationsheet.paste effect.
Does anyone have any ideas? Is it possible to modify roberts code to have the desired effect or is there an even simpler solution, such as a variation on the .copy method that actually includes underlying filtered rows?
Many thanks,
Alex
I have a block of data which I want to select in order to copy it.
It begins in column A and runs to column AU. It begins in row 2 and runs down a number of rows (typically 2000 rows but it varies) until there is no data in the rows.
Column C is the KEY and has data all the way till the last row so we should use this to determine how far down we need to make the selection.
Roberts excellent solution:
Code:
[/FONT]
[FONT=Tahoma]Sub Macro1()[/FONT]
[FONT=Tahoma]Dim rngMyDataRange As Range[/FONT]
[FONT=Tahoma]Set rngMyDataRange = Range("A2:AU" & Range("C" & Rows.Count).End(xlUp).Row)[/FONT]
[FONT=Tahoma]End Sub[/FONT]
[FONT=Tahoma]
</PRE>
A problem remains: The block of data is often autofiltered by the user with the filter being applied to COLUMN C (the key column). I need to copy the ENTIRE block of data to a new sheet, while not removing the user defined autofilter as he doesnt want to lose his filter settings (a valid option is to remove the filter, remember the settings, execute the copy and reapply the filter, but there must surely be a simpler solution).
Robert suggested:
Code:
[FONT=Tahoma]Sub Macro1()[/FONT]
[FONT=Tahoma] Dim strSourceTab As String, _[/FONT]
[FONT=Tahoma] strDestinTab As String[/FONT]
[FONT=Tahoma] Dim lngLastRow As Long[/FONT]
[FONT=Tahoma] 'Source tab name (change to suit)[/FONT]
[FONT=Tahoma] strSourceTab = "Sheet1"[/FONT]
[FONT=Tahoma] 'Destination (output) tab name (change to suit)[/FONT]
[FONT=Tahoma] strDestinTab = "Sheet2"[/FONT]
[FONT=Tahoma] 'http://excelvbamacro.com/how-to-find-the-last-row-that-contain-data-in-excel.html[/FONT]
[FONT=Tahoma] lngLastRow = Sheets(strSourceTab).UsedRange.Row - 1 + Sheets(strSourceTab).UsedRange.Rows.Count[/FONT]
[FONT=Tahoma] With Sheets(strDestinTab).Range("A2:AU" & lngLastRow)[/FONT]
[FONT=Tahoma] .Formula = "=" & strSourceTab & "!A2"[/FONT]
[FONT=Tahoma] .Value = .Value 'Converts the above formula (link) range to values. Comment out / delete if not needed.[/FONT]
[FONT=Tahoma] End With[/FONT]
[FONT=Tahoma]End Sub[/FONT]
</PRE>
Which is a nice attempt but unfortunately I need to simulate the effects of a plain sourcesheet.copy, destinationsheet.paste effect.
Does anyone have any ideas? Is it possible to modify roberts code to have the desired effect or is there an even simpler solution, such as a variation on the .copy method that actually includes underlying filtered rows?
Many thanks,
Alex