I need help.
In the below mentioned code I need to change the Target.Address which is A13 from a single cell to a range say A20:A30. I am unable to do the same as i am new to VBA. Can someone pl. correct the code for me
Thanks
Prakash
In the below mentioned code I need to change the Target.Address which is A13 from a single cell to a range say A20:A30. I am unable to do the same as i am new to VBA. Can someone pl. correct the code for me
Code:
Option Explicit
Dim strOriginalEntry As String
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iReply As Integer
If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "$A$13" And Target <> vbNullString Then ' Change to Validated cell
If WorksheetFunction.CountIf(Range("Names"), Target) = 0 Then 'New Name
Application.EnableEvents = False 'Prevent Change Event Firing again while code is running.
'Ask if they wish to add the name or not.
iReply = MsgBox("The name " & Target & _
" is not part of the list, do you wish to add it.", _
vbYesNoCancel + vbQuestion, "ozgrid.com")
If iReply = vbCancel Then 'Cancelled so restore orginal text
Target = strOriginalEntry
ElseIf iReply = vbNo Then
'Don't add to list. That is do nothing
Else 'Add the new name to the cell below the last name in the named range "Names"
Range("Names").Cells(1, 1).End(xlDown)(2, 1) = Target
End If
End If
End If
Application.EnableEvents = True 'Allow Events
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Pass orginal Text to the Module level Variable "strOriginalEntry"
If Target.Address = "$A$13" Then strOriginalEntry = Target
End Sub
Thanks
Prakash