mrMozambique
Board Regular
- Joined
- Mar 9, 2005
- Messages
- 97
Greetings, all. I have a macro that I recorded to copy a range from a sheet (Districts) and paste the values into a series of other sheets. The range is fixed width (2 columns), but can grow or shrink in length based on a filter I have set up in adjacent columns. So, the process is that I filter column C for Not Null and then copy and paste the resulting contents from columns A and B into another sheet (PP).
When I record the Macro I use the XLDown to select the length, but I can't use XLRight because it will extend to column C or beyond. The macro has an absolute Range selection (A4:B8). When I add a new district and run the macro, it doesn't capture it because it's in row 9.
My question is how to I make the selection of my range relative so it will grow as my data grow? Any help is greatly appreciated.
When I record the Macro I use the XLDown to select the length, but I can't use XLRight because it will extend to column C or beyond. The macro has an absolute Range selection (A4:B8). When I add a new district and run the macro, it doesn't capture it because it's in row 9.
My question is how to I make the selection of my range relative so it will grow as my data grow? Any help is greatly appreciated.
Code:
Application.Goto Reference:="community"
ActiveSheet.Unprotect
ActiveSheet.Range("$A$3:$G$202").AutoFilter Field:=3, Criteria1:="<>"
Range("A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range("A4:B8").Select
Sheets("PP").Select
ActiveSheet.Unprotect
Range("B5").Select
Sheets("Districts").Select
Selection.Copy
Sheets("PP").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFiltering:=True
Sheets("Districts").Select
ActiveSheet.Range("$A$3:$G$202").AutoFilter Field:=3