Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Vatiable range

I need to expand or reduce a range named "Database
I need to use (I guess) OffSet to select 4 adjacent col's

I started with this

Range("B6").Select
Range(Selection, Selection.End(xlDown)).Select
Range("Database").CurrentRegion.Name = "Database"

How do I do this?

oldjay
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Vatiable range

Hi Oldjay,

Try something like:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim Rng As Range
Dim iRow As Long

Set SH = ActiveSheet '<<==== CHANGE

With SH
iRow = .Range("B" & Rows.Count).End(xlUp).Row

Set Rng = .Range("B2:E" & iRow)
Rng.Name = "Databse"
End With
End Sub
'<<=============


---
Regards,
Norman



"Oldjay" wrote in message
...
I need to expand or reduce a range named "Database
I need to use (I guess) OffSet to select 4 adjacent col's

I started with this

Range("B6").Select
Range(Selection, Selection.End(xlDown)).Select
Range("Database").CurrentRegion.Name = "Database"

How do I do this?

oldjay



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Vatiable range

Why not just use a defined name to self adjust the range
insertnamedefinename it as desired "myrng"in the refers to box
=offset($a$1,1,0,counta($a:$a)-1,6)
look in the help index for OFFSET. Modify to suit
BTW. In your macros, selections are RARELY necessary or desirable


--
Don Guillett
SalesAid Software

"Oldjay" wrote in message
...
I need to expand or reduce a range named "Database
I need to use (I guess) OffSet to select 4 adjacent col's

I started with this

Range("B6").Select
Range(Selection, Selection.End(xlDown)).Select
Range("Database").CurrentRegion.Name = "Database"

How do I do this?

oldjay


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Vatiable range

To supplement Norman's code to work with unknown column numbers also:

Public Sub Tester()
Dim SH As Worksheet
Dim Rng As Range
Dim iRow As Long
Dim iCol As Long

Set SH = ActiveSheet '<<==== CHANGE
iCol = Cells(2, Columns.Count).End(xlToLeft).Column
With SH
iRow = .Range("B" & Rows.Count).End(xlUp).Row

Set Rng = .Range((Cells(2, 2)), (Cells(iRow, iCol)))
Rng.Name = "Databse"
End With
End Sub

Mike F
"Oldjay" wrote in message
...
I need to expand or reduce a range named "Database
I need to use (I guess) OffSet to select 4 adjacent col's

I started with this

Range("B6").Select
Range(Selection, Selection.End(xlDown)).Select
Range("Database").CurrentRegion.Name = "Database"

How do I do this?

oldjay



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 337
Default Vatiable range

Many Thanks !

oldjay

"Norman Jones" wrote:

Hi Oldjay,

Try something like:

'=============
Public Sub Tester()
Dim SH As Worksheet
Dim Rng As Range
Dim iRow As Long

Set SH = ActiveSheet '<<==== CHANGE

With SH
iRow = .Range("B" & Rows.Count).End(xlUp).Row

Set Rng = .Range("B2:E" & iRow)
Rng.Name = "Databse"
End With
End Sub
'<<=============


---
Regards,
Norman



"Oldjay" wrote in message
...
I need to expand or reduce a range named "Database
I need to use (I guess) OffSet to select 4 adjacent col's

I started with this

Range("B6").Select
Range(Selection, Selection.End(xlDown)).Select
Range("Database").CurrentRegion.Name = "Database"

How do I do this?

oldjay




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
How do I enter formula sum(range+range)*0.15 sumif(range=3) tkw Excel Discussion (Misc queries) 2 October 1st 09 09:17 PM
Excel Addin:Setting the range to the Excel.Range object range prop Rp007 Excel Worksheet Functions 5 November 24th 06 04:30 PM
Range Question / error 1004: method Range of object Worksheet has failed Paul Excel Programming 3 April 7th 05 02:56 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM
how to? set my range= my UDF argument (range vs. value in range) [advanced?] Keith R[_3_] Excel Programming 2 August 11th 03 05:55 PM


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