ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Attn: DP - Automating a dependent list - Code not working (https://www.excelbanter.com/excel-programming/353427-attn-dp-automating-dependent-list-code-not-working.html)

Chiku

Attn: DP - Automating a dependent list - Code not working
 
I had gotten some help to create the following code and could not get it to
work when I copied the spreadsheet to another workbook. It was for a
spreadsheet with two columns of about 21 rows and was supposed to automate a
dependent list, such that a user would select a value in the first column
which would generate a value in the second column but if they made a change
to the first column, the second column would reset to the first value of the
dependent list, forcing them to reselect the value in the dependent list.
(Let me know if this is unclear)
My problem is, the code does not work and I cannot figure out what the code
means line by lin - can you help please?

Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errHandler
Dim rng As Range
Dim intCounter As Integer
Dim varCellD As Variant
Dim varCellE As Variant

For intCounter = 4 To 25
varCellD = "D" & intCounter
varCellE = "E" & intCounter
Set curCell = Worksheets("Diveo Datacenter").Cells(2, intCounter)
If Not Intersect(Target, Me.Range(varCellD)) Is Nothing Then
If Target.Count 1 Then Exit Sub
Application.EnableEvents = False
Set rng = ActiveWorkbook.Names(Target.Value).RefersToRange
Me.Range(varCellE).Value = rng.Offset(0, 0).Value
End If
Next intCounter

errHandler:
MsgBox "Could not change dependent cell"
Exit Sub

exitHandler:
Application.EnableEvents = True
Exit Sub

End Sub



All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com