Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Code to change a named range

Hello,

I have a macro that runs and it ends up having to delete row 2 on 2
different sheets, which I do with..... which I am only showing a portion to
make it short and easy. This causes a problem is it causes my named range to
have a #REF where it used to say $B$2.

With .Worksheets("BO Ref List")
.Range("A1").PasteSpecial
.Columns("A:B").RemoveDuplicates Columns:=Array(1, 2),
Header:=xlYes
.Range("A2:B2").Delete Shift:=xlUp

With .Worksheets("FO Ref List")
.Range("A1").PasteSpecial
.Columns("A:B").RemoveDuplicates Columns:=Array(1, 2),
Header:=xlYes
.Range("A2:B2").Delete Shift:=xlUp

Here is the actual formula in my named range....
BOAssociate "=OFFSET('BO Ref List'!$B$2,0,0,COUNTA('BO Ref
List'!$B$2:$B$989),1)"
FOAssociate "=OFFSET('FO Ref List'!$B$2,0,0,COUNTA('FO Ref
List'!$B$2:$B$985),1)"

I have attempted using a few different things, but I am drawing a blank when
it comes to writing it into my macro to have it change the named range back
to the above.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 834
Default Code to change a named range


Why not just recreate it?

.Names.Add Name:="BOAssociate", RefersTo:="=OFFSET('BO Ref
List'!$B$2,0,0,COUNTA('BO Ref List'!$B$2:$B$989),1)"

--

HTH

Bob

"Brian" wrote in message
...
Hello,

I have a macro that runs and it ends up having to delete row 2 on 2
different sheets, which I do with..... which I am only showing a portion
to
make it short and easy. This causes a problem is it causes my named range
to
have a #REF where it used to say $B$2.

With .Worksheets("BO Ref List")
.Range("A1").PasteSpecial
.Columns("A:B").RemoveDuplicates Columns:=Array(1, 2),
Header:=xlYes
.Range("A2:B2").Delete Shift:=xlUp

With .Worksheets("FO Ref List")
.Range("A1").PasteSpecial
.Columns("A:B").RemoveDuplicates Columns:=Array(1, 2),
Header:=xlYes
.Range("A2:B2").Delete Shift:=xlUp

Here is the actual formula in my named range....
BOAssociate "=OFFSET('BO Ref List'!$B$2,0,0,COUNTA('BO Ref
List'!$B$2:$B$989),1)"
FOAssociate "=OFFSET('FO Ref List'!$B$2,0,0,COUNTA('FO Ref
List'!$B$2:$B$985),1)"

I have attempted using a few different things, but I am drawing a blank
when
it comes to writing it into my macro to have it change the named range
back
to the above.




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Code to change a named range


Why don't you simply add back the named range in the macro after you
delete the rows


ActiveWorkbook.Names.Add Name:=BOAssociate, RefersToR1C1:="=OFFSET('BO
Ref List'!$B$2,0,0,COUNTA('BO RefList'!$B$2:$B$989),1)"
ActiveWorkbook.Names.Add Name:=FOAssociate RefersToR1C1:="=OFFSET('FO
Ref List'!$B$2,0,0,COUNTA('FO RefList'!$B$2:$B$985),1)"


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?u=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=195192

http://www.thecodecage.com/forumz

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Code to change a named range

I was thinking too far into it and sometimes I just draw a blank. I knew it
was obvious, but I just couldnt think of it hehe.

"Bob Phillips" wrote:


Why not just recreate it?

.Names.Add Name:="BOAssociate", RefersTo:="=OFFSET('BO Ref
List'!$B$2,0,0,COUNTA('BO Ref List'!$B$2:$B$989),1)"

--

HTH

Bob

"Brian" wrote in message
...
Hello,

I have a macro that runs and it ends up having to delete row 2 on 2
different sheets, which I do with..... which I am only showing a portion
to
make it short and easy. This causes a problem is it causes my named range
to
have a #REF where it used to say $B$2.

With .Worksheets("BO Ref List")
.Range("A1").PasteSpecial
.Columns("A:B").RemoveDuplicates Columns:=Array(1, 2),
Header:=xlYes
.Range("A2:B2").Delete Shift:=xlUp

With .Worksheets("FO Ref List")
.Range("A1").PasteSpecial
.Columns("A:B").RemoveDuplicates Columns:=Array(1, 2),
Header:=xlYes
.Range("A2:B2").Delete Shift:=xlUp

Here is the actual formula in my named range....
BOAssociate "=OFFSET('BO Ref List'!$B$2,0,0,COUNTA('BO Ref
List'!$B$2:$B$989),1)"
FOAssociate "=OFFSET('FO Ref List'!$B$2,0,0,COUNTA('FO Ref
List'!$B$2:$B$985),1)"

I have attempted using a few different things, but I am drawing a blank
when
it comes to writing it into my macro to have it change the named range
back
to the above.




.

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
Can I change the reference to a named range via VBA? Bassman62 Excel Programming 7 March 22nd 09 05:52 PM
Change the value of particular cells in a Named Range RyanH Excel Programming 7 September 12th 08 08:19 PM
change named range geebee Excel Programming 5 August 14th 08 06:30 PM
Via code, making 2 named Ranges Indentical, upon change ML0940 Excel Programming 17 July 24th 08 08:11 AM
Change named range value Joe Boucher Excel Programming 2 September 30th 04 01:41 AM


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