Range names being deleted and altered

  • Thread starter Thread starter Todd Huttenstine
  • Start date Start date
T

Todd Huttenstine

Hey guys

This code deletes cells but it also deletes named ranges.
Is there anyway to protect my ranges where this does not
happen?


Dim found As Range
If CheckBox4.Value Then
Set found = Worksheets(1).Range("A4:Z4").Find(
_
What:=ComboBox1.Value, _
After:=Worksheets(1).Range("Z4"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
MatchCase:=False)
If Not found Is Nothing Then _
found.Resize(97, 1).Delete Shift:=xlToLeft
End If
 
Well, if you delete part of a named range, it is certainly going to get
deleted or altered!

Can you use ClearContents rather than Delete?
 
No clear will not work because I need for the next data in the column to be
shifted over to the lift so there will not be any columns with empty cells.
I dont want any gaps in my table.

Instead of clearing contents I used the current code but just inserted code
at the end to redifne my range names. Below is what I did. I dont know if
there is an easier way to perform this.

ActiveWorkbook.Names.Add Name:="area1", RefersToR1C1:="='Team
Data'!R5C1:R100C1"
ActiveWorkbook.Names.Add Name:="area2", RefersToR1C1:="='Team
Data'!R5C2:R100C2"
ActiveWorkbook.Names.Add Name:="area3", RefersToR1C1:="='Team
Data'!R5C3:R100C3"
ActiveWorkbook.Names.Add Name:="area4", RefersToR1C1:="='Team
Data'!R5C4:R100C4"
ActiveWorkbook.Names.Add Name:="area5", RefersToR1C1:="='Team
Data'!R5C5:R100C5"
ActiveWorkbook.Names.Add Name:="area6", RefersToR1C1:="='Team
Data'!R5C6:R100C6"
ActiveWorkbook.Names.Add Name:="area7", RefersToR1C1:="='Team
Data'!R5C7:R100C7"
ActiveWorkbook.Names.Add Name:="area8", RefersToR1C1:="='Team
Data'!R5C8:R100C8"
ActiveWorkbook.Names.Add Name:="area9", RefersToR1C1:="='Team
Data'!R5C9:R100C9"
ActiveWorkbook.Names.Add Name:="area10", RefersToR1C1:="='Team
Data'!R5C10:R100C10"
ActiveWorkbook.Names.Add Name:="area11", RefersToR1C1:="='Team
Data'!R5C11:R100C11"
ActiveWorkbook.Names.Add Name:="area12", RefersToR1C1:="='Team
Data'!R5C12:R100C12"
ActiveWorkbook.Names.Add Name:="area13", RefersToR1C1:="='Team
Data'!R5C13:R100C13"
ActiveWorkbook.Names.Add Name:="area14", RefersToR1C1:="='Team
Data'!R5C14:R100C14"
ActiveWorkbook.Names.Add Name:="area15", RefersToR1C1:="='Team
Data'!R5C15:R100C15"
ActiveWorkbook.Names.Add Name:="area16", RefersToR1C1:="='Team
Data'!R5C16:R100C16"
ActiveWorkbook.Names.Add Name:="area17", RefersToR1C1:="='Team
Data'!R5C17:R100C17"
ActiveWorkbook.Names.Add Name:="area18", RefersToR1C1:="='Team
Data'!R5C18:R100C18"
ActiveWorkbook.Names.Add Name:="area19", RefersToR1C1:="='Team
Data'!R5C19:R100C19"
ActiveWorkbook.Names.Add Name:="area20", RefersToR1C1:="='Team
Data'!R5C20:R100C20"
ActiveWorkbook.Names.Add Name:="area21", RefersToR1C1:="='Team
Data'!R5C21:R100C21"
ActiveWorkbook.Names.Add Name:="area22", RefersToR1C1:="='Team
Data'!R5C22:R100C22"
ActiveWorkbook.Names.Add Name:="area23", RefersToR1C1:="='Team
Data'!R5C23:R100C23"
ActiveWorkbook.Names.Add Name:="area24", RefersToR1C1:="='Team
Data'!R5C24:R100C24"
ActiveWorkbook.Names.Add Name:="area25", RefersToR1C1:="='Team
Data'!R5C25:R100C25"
ActiveWorkbook.Names.Add Name:="area26", RefersToR1C1:="='Team
Data'!R5C26:R100C26"
 
Todd, use this code to create your range names.

For ix = 1 To 26
ActiveWorkbook.names.Add Name:="area" & ix, RefersToR1C1:="='Team
Data'!R5C" & ix & ":R100C" & ix
Next ix

Cheers
N
 
Back
Top