View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Defining a variable length area for output.

Dim LastRow as long
dim myRng as range
with worksheets("OutputWorksheetNameHere")
lastrow = .cells(.rows.count,"AA").end(xlup).row
set myrng = .range("aa1").resize(lastrow,5)
'or
set myrng = .range("aa1:AE" & lastrow)
end with

'if you really needed to name that range:
myrng.name = "ValueOutput"

JHB wrote:

I haven't done Excel macros for some time, and find myself rusty --
having forgotten some key concepts!

At this point I need to develop a macro to define an area of variable
length which will be contain data to be output for an Access
application. I used to be able to do this, but have lost my previous
creations and just don't recall how to do it.

Say the area is to be defined as ValueOutput, and the area is AA1: AE
(x) where x is the length of the excel table. The length will be
defined the last line containing data in column AA. Hence, if there is
data in the range AA1:AE30, that would be the defined area
ValueOutput. However, the area could just as well be AA1:AE900! I am
trying to do this because Access gets all upset when I try and import
a series of blank records (which would be at the end of the table if I
used a defined set area).

I hope I have made my problem clear, and would appreciate any quick
solutions you may have.

The best I can do is the following (which I found in someone elses
spreadsheet), and it doesn't quite work it gives me AA1:AE1.. I wanted
A1:E133:

Sheets("data").Select
Range("AA1").Select
Set rng = Cells(Columns.Count, 4).End(xlUp)
Range(Range("a1"), rng).Resize(, 1).Name = "ValueOutput"

Thanks again!

John Baker


--

Dave Peterson