Tạo Validation list với nguồn là 1 Array (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

phuvacgach

Thành viên chính thức
Tham gia
13/3/11
Bài viết
56
Được thích
9
Dear anh chị,
Em cần tạo Droplist Validation vs data Source là Array mà không biết gán vào phần Formular như thế nào?
Anh chị nào biết giúp em nhé.

HTML:
Sub test()
    Dim Route2()
    Route2 = GetRoute2
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Route2"  'Cho nay em khong biet gan Formular nhu the nao?
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

Function GetRoute2()
    Dim Route2(1 To 3, 1 To 1)
        Route2(1, 1) = "a"
        Route2(2, 1) = "b"
        Route2(3, 1) = "c"
    GetRoute2 = Route2
End Function
 
Dear anh chị,
Em cần tạo Droplist Validation vs data Source là Array mà không biết gán vào phần Formular như thế nào?
Anh chị nào biết giúp em nhé.

HTML:
Sub test()
    Dim Route2()
    Route2 = GetRoute2
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=Route2"  'Cho nay em khong biet gan Formular nhu the nao?
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

Function GetRoute2()
    Dim Route2(1 To 3, 1 To 1)
        Route2(1, 1) = "a"
        Route2(2, 1) = "b"
        Route2(3, 1) = "c"
    GetRoute2 = Route2
End Function

Nếu là 1 mảng thì nên tạo thành mảng 1 chiều, xong nối chúng lại bằng dấu phẩy
Mã:
Function GetRoute2()
  [COLOR=#ff0000]Dim Route2(1 To 3)
  Route2(1) = "a"
  Route2(2) = "b"
  Route2(3) = "c"[/COLOR]
  GetRoute2 = Route2
End Function
Mã:
Sub test()
  Dim Route2
  Dim list As String
  Dim rng As Range
  Route2 = GetRoute2
  [COLOR=#ff0000]list = Join(Route2, ",")[/COLOR]
  Set rng = Selection
  With rng.Validation
    .Delete
    [COLOR=#ff0000].Add 3, , , list[/COLOR]   
    .IgnoreBlank = True
  End With
End Sub
Chú ý các dòng code màu đỏ
 
Upvote 0

Bài viết mới nhất

Back
Top Bottom