YellowLabPro
06-10-2006, 05:13 PM
Here is code from the macro recorder, starting on line 3
Lastrow = ActSh.Cells(Rows.Count, 1).End(xlUp).Row
ActSh.Range("A4", ActSh.Cells(Lastrow, "F")).ClearContents
Sheets("DataEdited").Select
Range("L2:S2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("PCCombined_FF").Select
Range("A4").Select
ActiveSheet.Paste
Cells.Columns.AutoFit
My thought is to convert it are
#1- Remove the .Select from Sheets("DataEdited").Select and Range("L2:S2").Select
#2- Remove Range(Selection, Selection.End(xlDown)).Select and replace w/ Select Up, (not that it matters in my current data, but thought it would be good practice
#3- Set a variable for the Sheet it needs to copy from and copy to, so Remove Range("A4").Select & ActiveSheet.Paste and replace w/ one statment.
My Attempt:
Dim rngSource As Range
Dim rngTarget As Range
Dim ActSh As Worksheet
Dim TrgSh As Worksheet
Dim Lastrow As Long
Set ActSh = Sheets("PCCombined_FF")
Set TrgShFF = Sheets("DataEdited")
Lastrow = ActSh.Cells(Rows.Count, 1).End(xlUp).Row
Lastrow = TrgShff.Range(Rows.Count,12).End(xlUp).Row
ActSh.Range("A4", ActSh.Cells(Lastrow, "F")).ClearContents
TrgSh.Range("L4",TrgSh.Cells(Lastrow, "S")).copy Destination:=Range("A4",ActSh.Range("A4"))
Thanks for having a look
YLP
Lastrow = ActSh.Cells(Rows.Count, 1).End(xlUp).Row
ActSh.Range("A4", ActSh.Cells(Lastrow, "F")).ClearContents
Sheets("DataEdited").Select
Range("L2:S2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Sheets("PCCombined_FF").Select
Range("A4").Select
ActiveSheet.Paste
Cells.Columns.AutoFit
My thought is to convert it are
#1- Remove the .Select from Sheets("DataEdited").Select and Range("L2:S2").Select
#2- Remove Range(Selection, Selection.End(xlDown)).Select and replace w/ Select Up, (not that it matters in my current data, but thought it would be good practice
#3- Set a variable for the Sheet it needs to copy from and copy to, so Remove Range("A4").Select & ActiveSheet.Paste and replace w/ one statment.
My Attempt:
Dim rngSource As Range
Dim rngTarget As Range
Dim ActSh As Worksheet
Dim TrgSh As Worksheet
Dim Lastrow As Long
Set ActSh = Sheets("PCCombined_FF")
Set TrgShFF = Sheets("DataEdited")
Lastrow = ActSh.Cells(Rows.Count, 1).End(xlUp).Row
Lastrow = TrgShff.Range(Rows.Count,12).End(xlUp).Row
ActSh.Range("A4", ActSh.Cells(Lastrow, "F")).ClearContents
TrgSh.Range("L4",TrgSh.Cells(Lastrow, "S")).copy Destination:=Range("A4",ActSh.Range("A4"))
Thanks for having a look
YLP