不同工作表上的范围

时间:2012-11-01 19:01:45

标签: combobox range

我正在尝试从另一个工作表中加载一个带有数组(范围)标签的组合框。如果我在范围内使用“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

1 个答案:

答案 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