Make range dynamic

pboltonchina

Well-known Member
Joined
Apr 24, 2008
Messages
1,117
Hi everyone and thanks for looking. I use the code below to copy a range and add it to the bottom of the copied range and then print it out. It;s basically a Fire sheet for work where column A has names in 2 sections. When I add or delete a name I have to change the offset in the macro to suit. I would like to make this dynamic so it detects any name changes itself and adjusts the range accordingly.
Code:
Sub AddOneWeek()
Application.ScreenUpdating = False
Application.EnableEvents = False
Cells(Rows.Count, "A").End(xlUp).Offset(-40).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Copy Destination:=Cells(Rows.Count, "A").End(xlUp).Offset(2)
Cells(Rows.Count, "A").End(xlUp).Offset(-40).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Rows.AutoFit
Cells(Rows.Count, "A").End(xlUp).Offset(-40).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).PrintOut Copies:=1, Collate:=True
Cells(Rows.Count, "A").End(xlUp).Offset(-40).Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

There are 2 sections to the copied data with the names duplicated.
First section
Excel Workbook
ABCDEFGHIJKLMNO
708NAMESATFireSUNFireMONFireTUESFireWEDFireTHURFireFRIFire
709Name 1
710Name 2
711Name 3
712Name 4
713Name 5
714Name 6
715Name 7
716Name 8
717Name 9
718Name 10
719Name 11
720Name 12
721Name 13
722
723Fire co-ordinators signitureDate
724
725Overtime request form for week ending:07/05/2010
Checklist 2010


second section
Excel Workbook
ABCDEFGHIJKLMNOPQR
726
727Enter amount of overtime you are requesting
728
729SATSUNMONTUEWEDTHURFRICOMMENTS
730NAMEPREPOSTPREPOSTPREPOSTPREPOSTPREPOST
731Name 1
732Name 2
733Name 3
734Name 4
735Name 5
736Name 6
737Name 7
738Name 8
739Name 9
740Name 10
741Name 11
742Name 12
743Name 13
744
745Autorised byDateSite Manager
Checklist 2010




Regards
Paul
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,224,616
Messages
6,179,912
Members
452,949
Latest member
beartooth91

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