-
Streamline code from MRecorder to Good Code Help
Here is code from the macro recorder, starting on line 3
[VBA]
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
[/VBA]
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:
[VBA]
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"))[/VBA]
Thanks for having a look
YLP
-
-
Hi Joseph,
I think you are correct in the last line of code. I have not tried your code, because it sounds like you were not able to get it to work based on my code, is that correct?
YLP
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules