troubleshooting Question

Update Values in Excel Data Validation

Avatar of Massimo Scola
Massimo ScolaFlag for Switzerland asked on
Microsoft ExcelRegular Expressions
4 Comments2 Solutions368 ViewsLast Modified:
Hello everyone

I have a problem with the data validation with lists in Excel.
Please have a look at my sample spreadsheet and my code.

The workbook has two sheets: name and customer.

I defined a name (called name) in name and I used data validation with lists in the sheet 'customer'. I set the data validation to accept data from name.only.  So far, so good.

It can happen that I want to change the name of a customer, or whathever is in a name. This is, after all, only an example. Unfortunately, once I've changed the value, it is not automatically updated in the the lists. I have to go through each cell, or in this example: row, that contains data validation/list and change the value manually by selecting it from the pulldown menu. That's ok if I only have a few records, but it will be cumbersome once the spreadsheet is populated with a lot of data.

I decided to write a VBA code which does this job, and it works. I put the code into the worksheet name. But there is a bug: Every time I add a new name in name, the new value is added to the first empty row and each row till number 65536. Annoying.

Any ideas what I'm doing wrong? How would you fix this?

Thanks a lot

Massimo






Option Explicit
Dim strName As String

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If Not Intersect(Target, Range("Name")) Is Nothing Then
      If Target.Count = 1 Then strName = Target
   End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
   Dim rngZelle As Range
   Dim strStart As String
   Dim strNeu As String
   If Not Intersect(Target, Range("Name")) Is Nothing Then
      If Target.Count = 1 Then
         strNeu = Target
         With Worksheets("Customer").Columns(1)
            Set rngZelle = .Find(strName, lookat:=xlWhole)
            If Not rngZelle Is Nothing Then
               strStart = rngZelle.Address
               Do
                  .Cells(rngZelle.Row, 1) = strNeu
                  Set rngZelle = .FindNext(rngZelle)
                  If rngZelle Is Nothing Then Exit Do
               Loop While Not rngZelle Is Nothing And rngZelle.Address <> strStart
            End If
         End With
      End If
   End If
   End Sub
Data-Validation.xls
Name.png
dropdown.jpg
Adding-a-new-name1.jpg
Adding-a-new-name2.jpg
ASKER CERTIFIED SOLUTION
StephenJR

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros