Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Changing range name in loop

Hey group,

I'm having a problem with looping through a macro and
renaming a range accordingly.
First step i name my range . Which i can get. but when the
loop progresses im trying to have it change according to
the amount of times the procedure loops. i was hoping
someone could help me. Thank you in advance.


Jeff

P.s there are notes where im having difficulty



'''''''
Dim DMrng As String
Dim Fname As String
Dim Sierra As String, Yukon As String, Malibu As String
Dim Cnt As Integer
'''sets CNT initial value
Cnt = 0


'''''Loop in question begins
Do
Fname = ActiveWorkbook.Name

'''selects if there is only one cell in range

If ActiveCell.Offset(-1, 0).Value < "" Then Range
(Selection, Selection.End(xlUp)).Name = "DMrng" & Cnt

'' if multiple cells in range the selects
If ActiveCell.Offset(-1, 0).Value = "" Then
ActiveCell.Name = "DMrng" & Cnt

'XXXXXXXXXXXX here is the problem the name i can not
'''XXXXXXXXXXX GET range to be named
correctly'''''''''''''''''''''

Sierra = "=COUNTIF(" & "'" & Fname & "'!" & DMrng &
cnt",Sierra)"
Yukon = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Yukon"")"
Malibu = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Malibu"")"


ActiveCell.FormulaR1C1 = Sierra
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = Yukon
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Malibu

Cnt = Cnt + 1
loop until activecell.value= ""
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default Changing range name in loop

Why not just make your ranges dynamic so that they can expand and contract
automatically without a macro
refers to=
=offset($a$2,0,0,counta($a:$a)+1,5)
will autosize $a$2:$e$whateverrow

--
Don Guillett
SalesAid Software

"Jeff" wrote in message
...
Hey group,

I'm having a problem with looping through a macro and
renaming a range accordingly.
First step i name my range . Which i can get. but when the
loop progresses im trying to have it change according to
the amount of times the procedure loops. i was hoping
someone could help me. Thank you in advance.


Jeff

P.s there are notes where im having difficulty



'''''''
Dim DMrng As String
Dim Fname As String
Dim Sierra As String, Yukon As String, Malibu As String
Dim Cnt As Integer
'''sets CNT initial value
Cnt = 0


'''''Loop in question begins
Do
Fname = ActiveWorkbook.Name

'''selects if there is only one cell in range

If ActiveCell.Offset(-1, 0).Value < "" Then Range
(Selection, Selection.End(xlUp)).Name = "DMrng" & Cnt

'' if multiple cells in range the selects
If ActiveCell.Offset(-1, 0).Value = "" Then
ActiveCell.Name = "DMrng" & Cnt

'XXXXXXXXXXXX here is the problem the name i can not
'''XXXXXXXXXXX GET range to be named
correctly'''''''''''''''''''''

Sierra = "=COUNTIF(" & "'" & Fname & "'!" & DMrng &
cnt",Sierra)"
Yukon = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Yukon"")"
Malibu = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Malibu"")"


ActiveCell.FormulaR1C1 = Sierra
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = Yukon
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Malibu

Cnt = Cnt + 1
loop until activecell.value= ""



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Changing range name in loop


Don,

This is due to the procedure having to run continuely. I
wish to run the procedure multiple times and set it so
that no matter how many ranges there are it will work
through it all.

Thanks though for your advice

Jeff

-----Original Message-----
Why not just make your ranges dynamic so that they can

expand and contract
automatically without a macro
refers to=
=offset($a$2,0,0,counta($a:$a)+1,5)
will autosize $a$2:$e$whateverrow

--
Don Guillett
SalesAid Software

"Jeff" wrote in

message
...
Hey group,

I'm having a problem with looping through a macro and
renaming a range accordingly.
First step i name my range . Which i can get. but when

the
loop progresses im trying to have it change according to
the amount of times the procedure loops. i was hoping
someone could help me. Thank you in advance.


Jeff

P.s there are notes where im having difficulty



'''''''
Dim DMrng As String
Dim Fname As String
Dim Sierra As String, Yukon As String, Malibu As String
Dim Cnt As Integer
'''sets CNT initial value
Cnt = 0


'''''Loop in question begins
Do
Fname = ActiveWorkbook.Name

'''selects if there is only one cell in range

If ActiveCell.Offset(-1, 0).Value < "" Then Range
(Selection, Selection.End(xlUp)).Name = "DMrng" & Cnt

'' if multiple cells in range the selects
If ActiveCell.Offset(-1, 0).Value = "" Then
ActiveCell.Name = "DMrng" & Cnt

'XXXXXXXXXXXX here is the problem the name i can not
'''XXXXXXXXXXX GET range to be named
correctly'''''''''''''''''''''

Sierra = "=COUNTIF(" & "'" & Fname & "'!" & DMrng &
cnt",Sierra)"
Yukon = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Yukon"")"
Malibu = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Malibu"")"


ActiveCell.FormulaR1C1 = Sierra
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = Yukon
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Malibu

Cnt = Cnt + 1
loop until activecell.value= ""



.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Changing range name in loop

Hi Jeff,

Names don't quite work like that.

Try something like this:

Sub B()
Dim rng As Range
Dim c As Range
Dim n As Long: n = 1
Dim WS As Worksheet

Set rng = Selection
Set WS = ActiveSheet

For Each c In rng
WS.Names.Add "Name" & n, c.Address
n = n + 1
Next c
End Sub

HTH

Peter Beach

"Jeff" wrote in message
...
Hey group,

I'm having a problem with looping through a macro and
renaming a range accordingly.
First step i name my range . Which i can get. but when the
loop progresses im trying to have it change according to
the amount of times the procedure loops. i was hoping
someone could help me. Thank you in advance.


Jeff

P.s there are notes where im having difficulty



'''''''
Dim DMrng As String
Dim Fname As String
Dim Sierra As String, Yukon As String, Malibu As String
Dim Cnt As Integer
'''sets CNT initial value
Cnt = 0


'''''Loop in question begins
Do
Fname = ActiveWorkbook.Name

'''selects if there is only one cell in range

If ActiveCell.Offset(-1, 0).Value < "" Then Range
(Selection, Selection.End(xlUp)).Name = "DMrng" & Cnt

'' if multiple cells in range the selects
If ActiveCell.Offset(-1, 0).Value = "" Then
ActiveCell.Name = "DMrng" & Cnt

'XXXXXXXXXXXX here is the problem the name i can not
'''XXXXXXXXXXX GET range to be named
correctly'''''''''''''''''''''

Sierra = "=COUNTIF(" & "'" & Fname & "'!" & DMrng &
cnt",Sierra)"
Yukon = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Yukon"")"
Malibu = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Malibu"")"


ActiveCell.FormulaR1C1 = Sierra
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = Yukon
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Malibu

Cnt = Cnt + 1
loop until activecell.value= ""



  #5   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Changing range name in loop

Thanks a bunch

Jeff



-----Original Message-----
Hi Jeff,

Names don't quite work like that.

Try something like this:

Sub B()
Dim rng As Range
Dim c As Range
Dim n As Long: n = 1
Dim WS As Worksheet

Set rng = Selection
Set WS = ActiveSheet

For Each c In rng
WS.Names.Add "Name" & n, c.Address
n = n + 1
Next c
End Sub

HTH

Peter Beach

"Jeff" wrote in

message
...
Hey group,

I'm having a problem with looping through a macro and
renaming a range accordingly.
First step i name my range . Which i can get. but when

the
loop progresses im trying to have it change according to
the amount of times the procedure loops. i was hoping
someone could help me. Thank you in advance.


Jeff

P.s there are notes where im having difficulty



'''''''
Dim DMrng As String
Dim Fname As String
Dim Sierra As String, Yukon As String, Malibu As String
Dim Cnt As Integer
'''sets CNT initial value
Cnt = 0


'''''Loop in question begins
Do
Fname = ActiveWorkbook.Name

'''selects if there is only one cell in range

If ActiveCell.Offset(-1, 0).Value < "" Then Range
(Selection, Selection.End(xlUp)).Name = "DMrng" & Cnt

'' if multiple cells in range the selects
If ActiveCell.Offset(-1, 0).Value = "" Then
ActiveCell.Name = "DMrng" & Cnt

'XXXXXXXXXXXX here is the problem the name i can not
'''XXXXXXXXXXX GET range to be named
correctly'''''''''''''''''''''

Sierra = "=COUNTIF(" & "'" & Fname & "'!" & DMrng &
cnt",Sierra)"
Yukon = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Yukon"")"
Malibu = "=COUNTIF(" & "'" & Fname & "'!DMrng &
cnt,""Malibu"")"


ActiveCell.FormulaR1C1 = Sierra
ActiveCell.Offset(1, 0).Select
ActiveCell.FormulaR1C1 = Yukon
ActiveCell.Offset(1, 0).Select
ActiveCell.Value = Malibu

Cnt = Cnt + 1
loop until activecell.value= ""



.



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
reset the range of FOR loop Farooq Sheri Excel Discussion (Misc queries) 1 April 7th 09 08:05 PM
Loop through last cell/row of used range tkraju via OfficeKB.com Excel Discussion (Misc queries) 1 April 4th 09 04:45 PM
Excel VBA - changing variables during a loop ellis_x[_3_] Excel Programming 3 July 5th 04 08:44 AM
Increasing a range in a loop ric Excel Programming 4 April 26th 04 07:59 PM
Loop for changing cell formatting Matt Excel Programming 1 January 15th 04 03:47 PM


All times are GMT +1. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"