PC Review


Reply
Thread Tools Rate Thread

How can I use a variable in a cell reference? Ex: $A$1:$F$"X"

 
 
CorporateQAinTX
Guest
Posts: n/a
 
      9th Jun 2008
I have a set of data that may change at any time, but I need to print it
without having to reset the Print Area manually every time. I've got a
CountIf(A:A, "<>") equation set to count how far down the Print Area needs to
go. But how can I enter it into the range reference for as a variable? Oh and
this is eventually going to be part of several macros for computer illiterate
to use.
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      9th Jun 2008
You don't need macros. The print area is stored as a locally defined named
range. Go to the sheet that you want and select Insert -> Name -> Define ->
Select Print_Area

Change the absolute reference to a dynamic named range similar to this...

=offset(A1,0,0,counta("A:A"), counta("1:1"))

As elements are added to column A or row 1 the print area will grow (or
shrink)...
--
HTH...

Jim Thomlinson


"CorporateQAinTX" wrote:

> I have a set of data that may change at any time, but I need to print it
> without having to reset the Print Area manually every time. I've got a
> CountIf(A:A, "<>") equation set to count how far down the Print Area needs to
> go. But how can I enter it into the range reference for as a variable? Oh and
> this is eventually going to be part of several macros for computer illiterate
> to use.

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      9th Jun 2008
Usually you try to avoid using worksheet functions in VBA because they are
less eifficient then VBA functions. But if you are targeting the code for
people who are familar with worksheet functions I guess it is OK.

Here are other methods of getting the Last row

Lastrow = CountIf(A:A, "<>")

If you have continuous data without any blank cells then use this

LastRow = Range("A1").end(xldown).row

If you have blank rows then you need to go to the end of the workbook row
65536 and move up until you find data. Because Excel 2007 has move than
65536 rows use Rows.Count which will work for either version of excel and get
the bottom of the worksheet.

LastRow = Range("A" & Rows.Count).end(xlup).Row

If you don't know which column contains the Last Row here is another way of
getting the LastRow


LastRow = Cells.SpecialCells(Type:=xlCellTypeLastCell).Row

Now Print the artea using the instruction below
---------------------------------------------------------------------
Range("A1:F" & LastRow.Printout


-------------------------------------------------

"CorporateQAinTX" wrote:

> I have a set of data that may change at any time, but I need to print it
> without having to reset the Print Area manually every time. I've got a
> CountIf(A:A, "<>") equation set to count how far down the Print Area needs to
> go. But how can I enter it into the range reference for as a variable? Oh and
> this is eventually going to be part of several macros for computer illiterate
> to use.

 
Reply With Quote
 
CorporateQAinTX
Guest
Posts: n/a
 
      10th Jun 2008
I like the way you're using the Naming system. Thanks. And btw, the macros
aren't for this. Just a very small part of the entire workbook. Thanks again.

"Jim Thomlinson" wrote:

> You don't need macros. The print area is stored as a locally defined named
> range. Go to the sheet that you want and select Insert -> Name -> Define ->
> Select Print_Area
>
> Change the absolute reference to a dynamic named range similar to this...
>
> =offset(A1,0,0,counta("A:A"), counta("1:1"))
>
> As elements are added to column A or row 1 the print area will grow (or
> shrink)...
> --
> HTH...
>
> Jim Thomlinson
>
>
> "CorporateQAinTX" wrote:
>
> > I have a set of data that may change at any time, but I need to print it
> > without having to reset the Print Area manually every time. I've got a
> > CountIf(A:A, "<>") equation set to count how far down the Print Area needs to
> > go. But how can I enter it into the range reference for as a variable? Oh and
> > this is eventually going to be part of several macros for computer illiterate
> > to use.

 
Reply With Quote
 
CorporateQAinTX
Guest
Posts: n/a
 
      10th Jun 2008
I don't normally use worksheet functions in VB. But since this is hopefully
something that will be used after I leave this job, I want to make sure that
my replacement will be able to understand it. Thanks for the help. It was
definately not a way I thought of doing it.

"Joel" wrote:

> Usually you try to avoid using worksheet functions in VBA because they are
> less eifficient then VBA functions. But if you are targeting the code for
> people who are familar with worksheet functions I guess it is OK.
>
> Here are other methods of getting the Last row
>
> Lastrow = CountIf(A:A, "<>")
>
> If you have continuous data without any blank cells then use this
>
> LastRow = Range("A1").end(xldown).row
>
> If you have blank rows then you need to go to the end of the workbook row
> 65536 and move up until you find data. Because Excel 2007 has move than
> 65536 rows use Rows.Count which will work for either version of excel and get
> the bottom of the worksheet.
>
> LastRow = Range("A" & Rows.Count).end(xlup).Row
>
> If you don't know which column contains the Last Row here is another way of
> getting the LastRow
>
>
> LastRow = Cells.SpecialCells(Type:=xlCellTypeLastCell).Row
>
> Now Print the artea using the instruction below
> ---------------------------------------------------------------------
> Range("A1:F" & LastRow.Printout
>
>
> -------------------------------------------------
>
> "CorporateQAinTX" wrote:
>
> > I have a set of data that may change at any time, but I need to print it
> > without having to reset the Print Area manually every time. I've got a
> > CountIf(A:A, "<>") equation set to count how far down the Print Area needs to
> > go. But how can I enter it into the range reference for as a variable? Oh and
> > this is eventually going to be part of several macros for computer illiterate
> > to use.

 
Reply With Quote
 
CorporateQAinTX
Guest
Posts: n/a
 
      10th Jun 2008
Thanks again guys. I just wanted to list what I ended up doing so others will
have at least one more good option available.

=CountIf(A:A,"<>")
I knew that my data would only go to the F column, so I put another formula
below that one.
="$A$1:$F$"&(CellAbove)

This gave me a range that changes based on the count. Then I set the Print
Area to equal the second cell in my macro. It works great now.


"CorporateQAinTX" wrote:

> I have a set of data that may change at any time, but I need to print it
> without having to reset the Print Area manually every time. I've got a
> CountIf(A:A, "<>") equation set to count how far down the Print Area needs to
> go. But how can I enter it into the range reference for as a variable? Oh and
> this is eventually going to be part of several macros for computer illiterate
> to use.

 
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
Re: Changing a cell reference based on a "helper" cell Bowbender Microsoft Excel Discussion 4 30th Dec 2010 08:53 PM
Changing a cell reference based on a "helper" cell Bowbender Microsoft Excel Discussion 0 30th Dec 2010 03:44 PM
reference to a "global" variable from within an aspx page Pierre Microsoft ASP .NET 3 13th Jan 2006 02:22 PM
Excel VBA - go to worksheet "name" based on a cell reference ="Name" james007 Microsoft Excel Programming 2 8th Jul 2004 11:04 PM
Copying cell contents from a referred cell that is in reference to a "find" cell ZX210 Microsoft Excel Misc 1 26th Dec 2003 06:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:50 PM.