range problem

ricksimm

Board Regular
Joined
Apr 28, 2005
Messages
188
I can't seem to get this to work.
Code:
        With SourceZoneSiteListBox
                Set rng = Range(SourceZoneSiteList, Range(SourceZoneSiteList).End(xlDown))
                For E = 0 To .ListCount - 1
                        If .Selected(E) Then
                                For Each c In rng
                                        If c.Value = .List(E) Then
                                                hitSW = True
                                                Range(c.Address).Delete Shift:=xlShiftUp
                                                Exit For
                                        End If
                                Next c
                        End If
                Next E
                If hitSW = False Then
                        MsgBox "No collection site selected."
                        Sheets("Blank").Activate
                        Application.ScreenUpdating = True
                        CollectionZoneEntry.SetFocus
                        Exit Sub
                End If
                SourceZoneSiteListBox.Clear
                Set rng = Range(SourceZoneSiteList, Range(SourceZoneSiteList).End(xlDown))
                For Each c In rng
                        SourceZoneSiteListBox.AddItem c.Value
                Next c
        End With
I use this code to delete an entry from a range. It works ok until I delete the first entry in the range. When I do that the range name disappears. I know this is just my lack of knowledge about how ranges work but could someone please help. Can you also point me towards documentation on creating and manipulating ranges? I'm using Excel 2007. Thanks.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
What do you mean the range name disappears?

There are no named ranges in that code that I can see.

What exactly is the code meant to do?
 
Upvote 0
When I initially set up the range I inserted the name in Excel using-
Code:
                        ActiveWorkbook.Names.Add Name:=listNAME, RefersTo:=Range(LObjRange1)         ' add the table name to excel
the name that disappears is the same as whatever is contained in listName above. I just want to delete an entry in the range. if I delete the 1st entry in the range, the range name is removed from Excel.
 
Upvote 0

Forum statistics

Threads
1,214,970
Messages
6,122,514
Members
449,088
Latest member
RandomExceller01

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top