Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Automatically Defining Ranges

Sub Test()
Dim iLastRow As Long
Dim iStart As Long
Dim sName As String
Dim i As Long

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row
sName = Range("A1").Value
iStart = 1
For i = 2 To iLastRow
If Cells(i, "A").Value < sName Then
Range("A" & iStart & ":A" & i - 1).Name = "X_" & sName
sName = Cells(i, "A").Value
iStart = i
End If
Next i

End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


wrote in message
oups.com...
I have data that is going to change every month, and need a code that I
can use to define ranges automatically within that data. There will be
some months where certain codes are in the data, and other months where
it won't be there. So I likely would need to run the macro every
month. I will present an example:

The data will have seven columns, and will be sorted by column A, which
contains the codes needed to define the ranges:

Example:

Column A
ABEHS
ABEHS
ABEHS
ABEHS
BOOOT
BOOOT
BOOOT
CAHGT
CAHGT
DOORT

So what I would need the VBA code to do is define the first four rows
as a defined range called "ABEHS", the next 3 to be defined as "BOOOT",
etc. Remember, the data changes every month - so next month, the
first 10 rows may be ABEHS...or perhaps I will have no ABEHS data at
all.



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
Defining Ranges Steve Excel Worksheet Functions 5 May 28th 05 07:41 AM
Automatically Defining Ranges Patrick Molloy[_2_] Excel Programming 0 May 5th 05 07:39 AM
Re-defining Ranges in VBA aehan Excel Programming 3 March 24th 05 05:15 PM
Defining ranges in VB code Rachael Moody Excel Programming 5 January 27th 04 02:21 PM
Defining Ranges Greg Ghavalas Excel Programming 2 July 9th 03 10:10 PM


All times are GMT +1. The time now is 06:34 PM.

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"