well I have managed what I want to do after a fashion... I still have a few issues but this is what I've managed so far.
Option Explicit
Dim OldValue As String ' Variable Needed to Remove old Named Ranges
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$B$11" Then ' Overall Range Naming for API Key
If Target.Cells.Count > 1 Then Exit Sub ' Makes sure there is only 1 cell changing
If Target <> "" Then ' This IF Sets Range Name only if Cell is Not Blank
Dim strName As String ' Defines Variable
strName = Replace(Target, " ", "_") ' Removes Spaces from Target Value
Range("C11").Name = "EveAPI3_" & strName ' Sets Range Name
End If ' End Range Nameing
If OldValue <> "" Then ' This If Deletes the Old Range Name, If there was one
Dim oldName As String ' More Variables
Dim oldName2 As String ' And More Variables
oldName2 = Replace(OldValue, " ", "_") ' Removes Spaces from Old Value
oldName = "EveAPI3_" & OldValue ' Sets what the Old Range Name was
On Error Resume Next ' Skips over if there is an Error
ActiveWorkbook.Names(oldName).Delete ' Deletes the Old Range Name
End If ' End Range Name Deleting
End If ' Ends API Key Range Naming
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Cells.Count > 1 Then ' Triggers If Statement if more than 1 cell is selected
MsgBox "Please select only one cell", vbCritical ' Error Message
ActiveCell.Select ' Removes Multiple Selection
End If ' End If
If Target.Address = "$B$11" Then ' If Statement checking value of Cell before Change
OldValue = Target ' Sets Variable
End If ' End If
End Sub
I still need to apply this to more than 1 cell, preferably a range of cells or even a full column
Bookmarks