Plz help me with my simple macro !

Jchicoine

New Member
Joined
Apr 29, 2002
Messages
22
Hi ! I'm not very good with macros but here the macro I did with the help of the recorder and I would like someone to help me in order to do what I really want !

I have some employees here and I would like to create a macro which will give me the possibility to add an employee during the year. All my employees are in the column A. So I would like a macro which will choose the sheets I want, find the first empty row in the column A, insert another entire empty row below that row and copy the informations in the row of the last employee from the list on the first empty row in column A.

Thanks a lot in advance !

Here's the code I came up :

Sub addemployee()
Sheets(Array("January", "February", "March")).Select
Sheets("January").Activate
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.Insert Shift:=xlDown
Rows("3:3").Select
Selection.AutoFill Destination:=Rows("3:4"), Type:=xlFillDefault
Rows("3:4").Select
Range("A4").Select
Selection.ClearContents
End Sub
 

Some videos you may like

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
Not tested, but I think this should work:

Code:
Sub addemployee() 
   Sheets(Array("January", "February", "March")).Select 
   Sheets("January").Activate 
   Range("A1").End(xlDown).EntireRow.Select 
   Selection.Copy 
   Selection.Offset(1, 0).Resize(,1).Select 
   Selection.Paste 
   Selection.ClearContents 
End Sub
 

Jchicoine

New Member
Joined
Apr 29, 2002
Messages
22
Thanks again for the info !

So far so good it works but I have a bug in the last line. Do you know why ?

Sheets(Array("January")).Select
Sheets("January").Activate
Range("A1").End(xlDown).Offset(1, 0).EntireRow.Select
Selection.Insert Shift:=xlDown
Selection.End(xlUp).EntireRow.Select
Selection.Copy
Selection.Offset(1, 0).Resize(, 1).Select
Selection.Paste

Thanks again sir !
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
I always forget that Paste is a method of the Worksheet object and not of the Range object. Anyway, I have tested this:

Code:
Sub Test()
Sheets(Array("January")).Select
Sheets("January").Activate
Range("A1").End(xlDown).EntireRow.Select
Selection.Copy Selection.Offset(1, 0).Resize(, 1)
End Sub

There is no need to insert a row beneath the last used cell, because it is already there. And the Copy method accepts a Destination argument, so I have used that instead of the Paste method.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,804
Messages
5,598,140
Members
414,214
Latest member
marketingnumbersguy

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
Top