kak @Herry
Lalu kalau cell target nya diubah seperti gambar terlampir, code VBA nya gimana. saya coba begini tidak berhasil.
Private Sub Worksheet_Activate()
Dim Sw As Worksheet, Hw As Worksheet, range1 As Range, rng As Range, RowSumber As Long
Application.ScreenUpdating = False
Set Sw = Worksheets("Master Data")
Set Hw = Worksheets("List")
RowSumber = Sw.Range("A" & Rows.Count).End(xlUp).Row
Set range1 = Sw.Range("A2:A" & RowSumber)
Set rng = Hw.Range("A9")
Hw.Range("A9:B9") = vbNullString
With rng.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="='" & Sw.Name & "'!" & range1.Address
End With
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Sw As Worksheet, Hw As Worksheet, range1 As Range, rng As Range, RowSumber As Long, LastColumn As Long
Dim Awal As Long, ColumnSumber As Variant
Application.ScreenUpdating = False
Set Sw = Worksheets("Master Data")
Set Hw = Worksheets("List")
If Target.Address = "$A$9" Then Hw.Range("B9") = vbNullString
If Target.Address = "$B$9" Then
With Sw
LastColumn = .Cells(1, .Columns.Count).End(xlToLeft).Column
For Awal = 2 To LastColumn
If Hw.Range("A9") = .Cells(1, Awal) Then
ColumnSumber = Split((Columns(Awal).Address(, 0)), ":")(0) '===> convert Angka to Abjad Column
RowSumber = Sw.Range(ColumnSumber & Rows.Count).End(xlUp).Row
Set range1 = .Range(ColumnSumber & "2:" & ColumnSumber & RowSumber)
Set rng = Hw.Range("B9")
If RowSumber > 2 Then
With rng.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="='" & Sw.Name & "'!" & range1.Address
End With
ElseIf RowSumber = 2 Then
X = .Cells(2, ColumnSumber)
With rng.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=X
End With
Else
MsgBox "Tidak Ada Jenis Barang Di Kategori ini"
End If
End If
Next Awal
End With
End If
Application.ScreenUpdating = True
End Sub