PC Review


Reply
Thread Tools Rate Thread

AutoFill Row Numbers & Print Area

 
 
=?Utf-8?B?c2FnZQ==?=
Guest
Posts: n/a
 
      23rd Apr 2007
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 With Quote
 
 
 
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      23rd Apr 2007
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 With Quote
 
=?Utf-8?B?c2FnZQ==?=
Guest
Posts: n/a
 
      23rd Apr 2007
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 With Quote
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      24th Apr 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding area codes only to phone numbers missing an area code RC Microsoft Excel Misc 4 12th Feb 2008 09:22 PM
set area in excel not giving me option to set print area? =?Utf-8?B?SiBMaXR0bGViZWFy?= Microsoft Excel Misc 3 30th May 2007 12:49 AM
How do you turn off a print area for a page? (no print area) =?Utf-8?B?R3J1bmVu?= Microsoft Excel Misc 4 8th Oct 2005 07:46 PM
Q. Autofill question: Can I autofill alpha characters like I can numbers? George Microsoft Excel Programming 5 7th Aug 2004 10:33 AM
Re: Setting Print Area, includes text, numbers, charts & graphs Arawn Microsoft Excel Programming 3 28th Aug 2003 03:34 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:13 AM.