2012-11-01 62 views
0

我想從另一個工作表的標籤數組(範圍)加載組合框。如果我在範圍中使用「A4:PB4」而不是Cells方法,它將起作用。不知道爲什麼這不起作用。我使用範圍內的細胞正常範圍在不同的工作表

Private Sub ComboBox1_GotFocus() 

Dim myArray As Variant 
lastcol = Worksheets("data").Range("A4").End(xlToRight).Column 
myArray = WorksheetFunction.Transpose(Worksheets("data").Range(Cells(4, 1), Cells(4, lastcol))) 
With Me.ComboBox1 
    .List = myArray 
End With 

End Sub 
+0

是誰? –

回答

0
Private Sub ComboBox1_GotFocus() 

    Dim myArray As Variant 

    lastcol = Worksheets("data").Range("A4").End(xlToRight).Column 
    With Worksheets("data") 
    Set SourceRng = .Range(.Cells(4, 1), .Cells(4, lastcol)) 
    End With 
    myArray = WorksheetFunction.Transpose(SourceRng) 
    With Me.ComboBox1 
    .List = myArray 
    End With 

End Sub