Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro to auto Name a Range based on criteria

Hello,
This is somewhat complicated, so I will try to explain best I can. I have a
data worksheet is a wb that is update weekly and new data is dumped on top of
it. In the data, there are 250 rows with 6 columns. Column B has various
departments and Column C has the positions that go with the department. For
certain validation criteria, I need to name the range of only the positions
(col C) that are in each department. So the data looks like this:
Front Desk Agent
Front Desk Supervisor
Front Desk Asst Mgr
Front Desk Mgr
Housekeeping Housekeeper
Housekeeping Houseman
etc...etc...etc..

So, I would like to be able to run a macro and it would redefine the ranges
for Front Desk and only use the positions. Then go on to housekeeping and so
on.

Any assistance would be gratefull.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Macro to auto Name a Range based on criteria

Give this a go:

Sub NameThem()

Dim lRow As Long
Dim counter As Long
Dim Dept As String
Dim newDept As String
Dim sRow As Integer
Dim eRow As Integer
Dim chk As Range
Dim colB As Range

lRow = Cells(Rows.Count, 2).End(xlUp).Row + 1
Set colB = Range(Cells(2, 2), Cells(lRow, 2))
Dept = Trim(Cells(2, 2).Value)
newDept = Replace(Dept, " ", "")
sRow = 2
eRow = 2
For Each chk In colB
If chk.Value < Dept Then
ActiveWorkbook.Names.Add Name:=newDept, _
RefersToR1C1:="=Sheet2!R" & sRow & "C3:R" & eRow & "C3"
Dept = chk.Value
newDept = Replace(Dept, " ", "")
sRow = chk.Row
eRow = chk.Row
Else
eRow = chk.Row
End If
Next chk
End Sub

Hope this helps
Rowan

"Mike R." wrote:

Hello,
This is somewhat complicated, so I will try to explain best I can. I have a
data worksheet is a wb that is update weekly and new data is dumped on top of
it. In the data, there are 250 rows with 6 columns. Column B has various
departments and Column C has the positions that go with the department. For
certain validation criteria, I need to name the range of only the positions
(col C) that are in each department. So the data looks like this:
Front Desk Agent
Front Desk Supervisor
Front Desk Asst Mgr
Front Desk Mgr
Housekeeping Housekeeper
Housekeeping Houseman
etc...etc...etc..

So, I would like to be able to run a macro and it would redefine the ranges
for Front Desk and only use the positions. Then go on to housekeeping and so
on.

Any assistance would be gratefull.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro to auto Name a Range based on criteria

PERFECT!!! Thanks!
Mike

"Rowan" wrote:

Give this a go:

Sub NameThem()

Dim lRow As Long
Dim counter As Long
Dim Dept As String
Dim newDept As String
Dim sRow As Integer
Dim eRow As Integer
Dim chk As Range
Dim colB As Range

lRow = Cells(Rows.Count, 2).End(xlUp).Row + 1
Set colB = Range(Cells(2, 2), Cells(lRow, 2))
Dept = Trim(Cells(2, 2).Value)
newDept = Replace(Dept, " ", "")
sRow = 2
eRow = 2
For Each chk In colB
If chk.Value < Dept Then
ActiveWorkbook.Names.Add Name:=newDept, _
RefersToR1C1:="=Sheet2!R" & sRow & "C3:R" & eRow & "C3"
Dept = chk.Value
newDept = Replace(Dept, " ", "")
sRow = chk.Row
eRow = chk.Row
Else
eRow = chk.Row
End If
Next chk
End Sub

Hope this helps
Rowan

"Mike R." wrote:

Hello,
This is somewhat complicated, so I will try to explain best I can. I have a
data worksheet is a wb that is update weekly and new data is dumped on top of
it. In the data, there are 250 rows with 6 columns. Column B has various
departments and Column C has the positions that go with the department. For
certain validation criteria, I need to name the range of only the positions
(col C) that are in each department. So the data looks like this:
Front Desk Agent
Front Desk Supervisor
Front Desk Asst Mgr
Front Desk Mgr
Housekeeping Housekeeper
Housekeeping Houseman
etc...etc...etc..

So, I would like to be able to run a macro and it would redefine the ranges
for Front Desk and only use the positions. Then go on to housekeeping and so
on.

Any assistance would be gratefull.

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
Summing a range of cells based on criteria in another range Jack Excel Worksheet Functions 2 November 5th 09 01:46 AM
Summing based on a range of criteria Mike Excel Discussion (Misc queries) 3 June 16th 09 07:05 PM
Sum based on Range Criteria ddate Excel Worksheet Functions 2 August 3rd 07 10:16 PM
MIN within range based on criteria StevenL Excel Discussion (Misc queries) 9 July 11th 05 11:33 PM
group rows in a range based on criteria from another range (vba) Andy Excel Programming 2 April 28th 04 03:26 AM


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