Data validation updates

jqfranco

New Member
Joined
Dec 27, 2017
Messages
28
I have an Excel file with two worksheets.


In the "ListSource" spreadsheet on lines A2; A150, I have the list that will feed the droplist.


In the "DropList" worksheet I have a droplist on the lines F3: F503.


When I change a value in my list in "ListSource", this change is reflected in the spreadsheet "DropList", in all cells that had the old value, which is correct.


The problem is that when I add a value in the list in "ListSource", in the "DropList" worksheet, in all droplist cells that are missing values, it adds the new value.


For example, if your I have cells written between the lines F3: F20, it puts the new value in the cells between F21 and F503, without having done anything at all.


The code is placed in the Worksheet ListSource Change

Code:
Private Sub Worksheet_Change (ByVal Target As Range)
Application.ScreenUpdating = False
Dim count_cells As Integer
Dim new_value As String
Dim old_value As String
Dim Rng As Range
For count_cells = 1 To Range ("A1"). CurrentRegion.Rows.Count - 3
    Set rng = Worksheets ("DropList") Range ("F4: F503")
    If Intersect (Target, Range ("A" & count_cells + 3)) Is Nothing Then
    Else
        Application.EnableEvents = False
        new_value = Target.Value
        Application.Undo
        old_value = Target.Value
        Target.Value = new_value
        rng.Replace What: = old_value, Replacement: = new_value
        Target.Select
    End If
Next count_cells
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub



If someone can help me solve this problem, thank you in advance.


Happy New Year 2018 for all of you
 
Last edited by a moderator:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Forum statistics

Threads
1,224,828
Messages
6,181,210
Members
453,023
Latest member
alabaz

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