Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default AutoFill Row Numbers & Print Area

Hi, I'm a newbie with macros and need some help. I have a spreadsheet with
data extracted by a macro and I've inserted Column A which is blank. I need
to include something in the macro to auto fill the row numbers in column A to
the end of the data. The number of rows is changeable.

Also I need something that will set the print area each time the macro is
run but the print area changes each time as well. I don't need to actually
print the document though, just set the area ready to print.


  #2   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default AutoFill Row Numbers & Print Area

Hi sage -

1. Add these statements to your macro to number the rows:

Set homeCell = Range("B1") '<<change to top, left-most data cell
rowCnt = homeCell.CurrentRegion.Rows.Count
For i = 1 To rowCnt
homeCell.Offset(i - 1, -1) = i
Next i

2. Add this statement to set the print range:
ActiveSheet.PageSetup.PrintArea = homeCell.CurrentRegion.Address

---
Jay


"sage" wrote:

Hi, I'm a newbie with macros and need some help. I have a spreadsheet with
data extracted by a macro and I've inserted Column A which is blank. I need
to include something in the macro to auto fill the row numbers in column A to
the end of the data. The number of rows is changeable.

Also I need something that will set the print area each time the macro is
run but the print area changes each time as well. I don't need to actually
print the document though, just set the area ready to print.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default AutoFill Row Numbers & Print Area

Thanks Jay, that worked beautifully....only one small problem, I need to
count the rows from row 2 (row 1 is headers). I changed the home cell to B2
but it counts one extra row at the bottom....how can I fix it?

Thanks
Sage

"Jay" wrote:

Hi sage -

1. Add these statements to your macro to number the rows:

Set homeCell = Range("B1") '<<change to top, left-most data cell
rowCnt = homeCell.CurrentRegion.Rows.Count
For i = 1 To rowCnt
homeCell.Offset(i - 1, -1) = i
Next i

2. Add this statement to set the print range:
ActiveSheet.PageSetup.PrintArea = homeCell.CurrentRegion.Address

---
Jay


"sage" wrote:

Hi, I'm a newbie with macros and need some help. I have a spreadsheet with
data extracted by a macro and I've inserted Column A which is blank. I need
to include something in the macro to auto fill the row numbers in column A to
the end of the data. The number of rows is changeable.

Also I need something that will set the print area each time the macro is
run but the print area changes each time as well. I don't need to actually
print the document though, just set the area ready to print.


  #4   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default AutoFill Row Numbers & Print Area

Hi Sage -

This version adjusts for the header row. Keep the homeCell set to the top,
left-most cell (B1). It's only purpose is to be reference point from which
to sense your data range (with the CurrentRegion property).

Also, once you run this you might notice that Excel shows the pagebreaks as
dashed lines on the screen. These can be annoying sometimes, especially if
you need to work on the sheet. The last statement in the procedure
suppresses them. You can also turn them off from the user interface menu by
clearing the [Page breaks] checkbox under |Tools|Options|{View Tab}|'Window
Options' category.

Sub sage()

Set homeCell = Range("B1") '<<change to top, left-most data cell
rowCnt = homeCell.CurrentRegion.Rows.Count
For i = 1 To rowCnt - 1
homeCell.Offset(i, -1) = i
Next i

ActiveSheet.PageSetup.PrintArea = homeCell.CurrentRegion.Address
ActiveSheet.DisplayPageBreaks = False '(turns pagebreak preview lines off)
End Sub

--
Jay

"sage" wrote:

Thanks Jay, that worked beautifully....only one small problem, I need to
count the rows from row 2 (row 1 is headers). I changed the home cell to B2
but it counts one extra row at the bottom....how can I fix it?

Thanks
Sage

"Jay" wrote:

Hi sage -

1. Add these statements to your macro to number the rows:

Set homeCell = Range("B1") '<<change to top, left-most data cell
rowCnt = homeCell.CurrentRegion.Rows.Count
For i = 1 To rowCnt
homeCell.Offset(i - 1, -1) = i
Next i

2. Add this statement to set the print range:
ActiveSheet.PageSetup.PrintArea = homeCell.CurrentRegion.Address

---
Jay


"sage" wrote:

Hi, I'm a newbie with macros and need some help. I have a spreadsheet with
data extracted by a macro and I've inserted Column A which is blank. I need
to include something in the macro to auto fill the row numbers in column A to
the end of the data. The number of rows is changeable.

Also I need something that will set the print area each time the macro is
run but the print area changes each time as well. I don't need to actually
print the document though, just set the area ready to print.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
set area in excel not giving me option to set print area? J Littlebear Excel Discussion (Misc queries) 4 April 23rd 23 09:04 PM
File, print area, clear area, is not working cblind New Users to Excel 2 September 12th 07 04:51 PM
How do you turn off a print area for a page? (no print area) Grunen Excel Discussion (Misc queries) 4 October 8th 05 07:46 PM
Q. Autofill question: Can I autofill alpha characters like I can numbers? George[_22_] Excel Programming 5 August 7th 04 10:33 AM
Setting Print Area, includes text, numbers, charts & graphs Arawn Excel Programming 3 August 28th 03 03:34 AM


All times are GMT +1. The time now is 11:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"