I "assume" that you're using a userform. Attached is a userform that contains: Initialize event: populates the listbox with Range Names in the workbookListbox Change Event: Selects Named Range (for display purposes)Delete Button: 1) Clears contents of Named Range selected in Listbox2) Deletes Named Range from list of Named Ranges3) Removes Named Range from Lisbox.
To test:Detach BOTH attachments into temp folder.In the VB Editor "Project
Explorer" panel, right-click and select "Import File..."select
"Form_Ranges.frm" from temp folder.
You can execute the "initialize" event to test,or you can create a macro that
contains: Form_Ranges.show
Paul-----------------------------------------
“Do all the good you can,
By all the means you can,
In all the ways you can,
In all the places you can,
At all the times you can,
To all the people you can,
As long as ever you can.” - John Wesley
-----------------------------------------
On Saturday, November 12, 2016 2:55 PM, jgscott3 <[email protected]>
wrote:
I have a listbox containing some range names. When the user selects one, I want
code to (1) clear the range to which the name refers, (2) delete the range
name, and (3) remove the range name from the listbox.
Thank you.
jgscott3--
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
https://www.facebook.com/discussexcel
FORUM RULES
1) Use concise, accurate thread titles. Poor thread titles, like Please Help,
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
NOTE : Don't ever post confidential data in a workbook. Forum owners and
members are not responsible for any loss.
---
You received this message because you are subscribed to the Google Groups "MS
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.
--
Are you =EXP(E:RT) or =NOT(EXP(E:RT)) in Excel? And do you wanna be? It’s
=TIME(2,DO:IT,N:OW) ! Join official Facebook page of this forum @
https://www.facebook.com/discussexcel
FORUM RULES
1) Use concise, accurate thread titles. Poor thread titles, like Please Help,
Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will not get
quick attention or may not be answered.
2) Don't post a question in the thread of another member.
3) Don't post questions regarding breaking or bypassing any security measure.
4) Acknowledge the responses you receive, good or bad.
5) Jobs posting is not allowed.
6) Sharing copyrighted material and their links is not allowed.
NOTE : Don't ever post confidential data in a workbook. Forum owners and
members are not responsible for any loss.
---
You received this message because you are subscribed to the Google Groups "MS
EXCEL AND VBA MACROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/excel-macros.
For more options, visit https://groups.google.com/d/optout.
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Form_Ranges
Caption = "Ranges"
ClientHeight = 2700
ClientLeft = 45
ClientTop = 375
ClientWidth = 3360
OleObjectBlob = "Form_Ranges.frx":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = "Form_Ranges"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Btn_Delete_Click()
Dim RangeName, RangeNo
Dim ws_Names, ws_Name
'------------------------------------------------
Set ws_Names = ActiveWorkbook.Names
'------------------------------------------------
' Read Selection from Userform
RangeNo = Form_Ranges.List_Ranges.ListIndex
RangeName = Form_Ranges.List_Ranges.List(RangeNo)
'------------------------------------------------
'Clear contents of selected Range
Range(RangeName).ClearContents
'------------------------------------------------
' Delete Named Range from list of Named Ranges
For Each ws_Name In ws_Names
If (ws_Name.Name = RangeName) Then
ws_Name.Delete
Exit For
End If
Next ws_Name
'------------------------------------------------
' remove Named Range from Userform List
If Form_Ranges.List_Ranges.ListCount >= 1 Then
'If no selection, choose last list item.
If Form_Ranges.List_Ranges.ListIndex = -1 Then
Form_Ranges.List_Ranges.ListIndex = _
Form_Ranges.List_Ranges.ListCount - 1
End If
Form_Ranges.List_Ranges.RemoveItem (Form_Ranges.List_Ranges.ListIndex)
End If
'------------------------------------------------
End Sub
Private Sub List_Ranges_Click()
Dim RangeName, RangeNo
RangeNo = Form_Ranges.List_Ranges.ListIndex
RangeName = Form_Ranges.List_Ranges.List(RangeNo)
Range(RangeName).Select
Debug.Assert True
End Sub
Private Sub UserForm_Initialize()
Dim ws_Names, ws_Name, inx
Form_Ranges.List_Ranges.Clear
inx = 0
Set ws_Names = ActiveWorkbook.Names
'---------------------------------------
' Find Named Ranges
'---------------------------------------
For Each ws_Name In ws_Names
Form_Ranges.List_Ranges.AddItem ws_Name.Name
Next ws_Name
End Sub
Form_Ranges.frx
Description: Binary data
