how to fix this Macros

nathan663

Board Regular
Joined
Dec 3, 2008
Messages
153
I have the following Macro:

ActiveWindow.SmallScroll Down:=21
Rows("39:39").Select
Selection.Copy
Sheets("Summary").Select
Rows("4:4").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B18").Select
Columns("B:B").EntireColumn.AutoFit
Range("D13").Select
Sheets("Individual - Non-Approved").Select
Range("A31:K31").Select

How can i amend this so when it pastes into the "summary" sheet it will look for the next available row, and not just row 4. as stated in the macro?

im guessing its a simple fix?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:

Code:
Dim lastrow As Long
lastrow = Sheets("Summary").Cells(Rows.Count, 1).End(xlUp).Row + 1
Rows("39:39").Copy
Sheets("Summary").Range("A" & lastrow).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Columns("B:B").EntireColumn.AutoFit
Sheets("Individual - Non-Approved").Range("A31:K31").Select

Dom
 
Last edited:
Upvote 0
Something like this:

Code:
Sub a()

Rows(39).Copy
freerow = Sheets("Summary").Rows(4).End(xlDown).Row + 1
Cells(freerow, 1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Columns("B:B").EntireColumn.AutoFit
Sheets("Individual - Non-Approved").Select
Range("A31:K31").Select

End Sub
 
Upvote 0
Nathan

In code, you generally do not have to activate/select things to work with them. In additions activation/selection is a relatively slow process so try to pick up tips about working without these actions.

Try this on a copy of your workbook.

Instead of ActiveSheet, you may want
Sheets("Individual - Non-Approved")
but I'm not certain about which sheet you are copying from.

<font face=Courier New>ActiveSheet.Rows("39").Copy<br><SPAN style="color:#00007F">With</SPAN> Sheets("Summary")<br>    .Range("A" & Rows.Count).End(xlUp).Offset(1) _<br>        .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _<br>            SkipBlanks:=False, Transpose:=<SPAN style="color:#00007F">False</SPAN><br>    .Columns("B").AutoFit<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>Application.CutCopyMode = False</FONT>
 
Upvote 0
Nathan

In code, you generally do not have to activate/select things to work with them. In additions activation/selection is a relatively slow process so try to pick up tips about working without these actions.

Try this on a copy of your workbook.

Instead of ActiveSheet, you may want
Sheets("Individual - Non-Approved")
but I'm not certain about which sheet you are copying from.

ActiveSheet.Rows("39").Copy
With Sheets("Summary")
.Range("A" & Rows.Count).End(xlUp).Offset(1) _
.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
.Columns("B").AutoFit
End With
Application.CutCopyMode = False


This was a recorded macro. I have only started working with macros in the last week or so. I am copying from Individual - Non Approved to the Summary Sheet
 
Upvote 0
This was a recorded macro. I have only started working with macros in the last week or so.
The macro recorder is a good place to start, but keep looking out for ways to improve that code because it mostly does not produce very efficient code.


I am copying from Individual - Non Approved to the Summary Sheet
Then I would change the first line of my suggested code to:

Sheets("Individual - Non-Approved").Rows("39").Copy
 
Upvote 0

Forum statistics

Threads
1,203,082
Messages
6,053,420
Members
444,662
Latest member
AaronPMH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top