Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 447
Default Set range to block of cells in Macro

I'm fairly new to Excel syntax and have written a macro to put a bunch of
data from various rows and columns on a worksheet into one block of data,
with the idea that I could name the block of data for grabbing it with an
outside application (Access).

I know where the corners of the block are, but I can't figure out the syntax
to use to define it. This is the closest I can get (RowCnt&ColCnt define the
upper left corner and EndRow&EndCol the lower right corner):

Set r1 = Range(Cells(RowCnt, ColCnt), Cells(EndRow, EndCol).End(xldown))

This works, but includes loads of empty rows below the block I'm interested
in; I'm presuming because of the "xldown" at the end, for which I haven't
found a list of optional substitutions for. The line gives an error without
the "xldown" part.

Can someone help me with the syntax? Also, if I do something like:
r1.name = "grabData"
Will that name be assigned to the range even after the macro ends?

Thanks!


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Set range to block of cells in Macro

Sub demo()
r1 = 2
c1 = 2
r2 = 10
c2 = 10
Set r = Range(Cells(r1, c1), Cells(r2, c2))
MsgBox r.Address
End Sub

--
Gary''s Student - gsnu200722


"Karen" wrote:

I'm fairly new to Excel syntax and have written a macro to put a bunch of
data from various rows and columns on a worksheet into one block of data,
with the idea that I could name the block of data for grabbing it with an
outside application (Access).

I know where the corners of the block are, but I can't figure out the syntax
to use to define it. This is the closest I can get (RowCnt&ColCnt define the
upper left corner and EndRow&EndCol the lower right corner):

Set r1 = Range(Cells(RowCnt, ColCnt), Cells(EndRow, EndCol).End(xldown))

This works, but includes loads of empty rows below the block I'm interested
in; I'm presuming because of the "xldown" at the end, for which I haven't
found a list of optional substitutions for. The line gives an error without
the "xldown" part.

Can someone help me with the syntax? Also, if I do something like:
r1.name = "grabData"
Will that name be assigned to the range even after the macro ends?

Thanks!


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 447
Default Set range to block of cells in Macro


Thanks! That worked and I've also confirmed that the range name works too!
Marvelous!



"Karen" wrote:

I'm fairly new to Excel syntax and have written a macro to put a bunch of
data from various rows and columns on a worksheet into one block of data,
with the idea that I could name the block of data for grabbing it with an
outside application (Access).

I know where the corners of the block are, but I can't figure out the syntax
to use to define it. This is the closest I can get (RowCnt&ColCnt define the
upper left corner and EndRow&EndCol the lower right corner):

Set r1 = Range(Cells(RowCnt, ColCnt), Cells(EndRow, EndCol).End(xldown))

This works, but includes loads of empty rows below the block I'm interested
in; I'm presuming because of the "xldown" at the end, for which I haven't
found a list of optional substitutions for. The line gives an error without
the "xldown" part.

Can someone help me with the syntax? Also, if I do something like:
r1.name = "grabData"
Will that name be assigned to the range even after the macro ends?

Thanks!


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
Macro and a range of cells ME Excel Discussion (Misc queries) 6 May 10th 07 05:48 PM
Using validation to block cells RiotLoadTime Excel Discussion (Misc queries) 8 August 10th 06 10:55 AM
Change block range into one column cbart Excel Discussion (Misc queries) 4 March 29th 06 10:14 PM
Macro to hide blank cells in a range Dave Excel Discussion (Misc queries) 1 February 1st 06 11:55 PM
copy a block of cells florin Excel Discussion (Misc queries) 2 October 12th 05 03:16 PM


All times are GMT +1. The time now is 11:16 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"