编译期望的错误数组 – Ubound – VBA

编译错误数组期望遇到错误。 我不正确地使用Ubound吗? 我应该宣布myarray("Measurement", "", "Nominal", "Low", "High", "", "")在开幕Dim声明? 如果是这样,那么我怎么办呢,我还有其他的声明呢?

  Private Sub Format_Parse_Replace() Dim i As Double Dim ws As Worksheet Set ws = ThisWorkbook.ActiveSheet Dim NomValue As String Dim myarray As String Dim rLastCell As Range Set rLastCell = ws.Cells.Find(What:="*", After:=ws.Cells(1, 1), LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False) 'MsgBox ("The last used column is: " & rLastCell.Column) Rows("4:6").EntireRow.Insert myarray = Array("Measurement", "", "Nominal", "Low", "High", "", "") Range("A2:A" & UBound(myarray) + 1) = _ WorksheetFunction.Transpose(myarray) For i = rLastCell.Column To 2 Step -1 'If Cells(1, i) = "Logbook" Then 'Columns(i).Delete 'End If 'Set Col = ColLett(rLastCell.Column) NomValue = ws.Cells(3, i).Value Columns(i).Cells(4).NumberFormat = "@" Columns(i).Cells(5).NumberFormat = "@" Columns(i).Cells(6).NumberFormat = "@" Columns(i).Cells(4) = SplitString(NomValue, ",", 4) Columns(i).Cells(5) = SplitString(NomValue, ",", 5) Columns(i).Cells(6) = SplitString(NomValue, ",", 6) Next i Rows(3).Delete End Sub 

谢谢

Excel帮助:数组函数:返回包含数组的variables。

 Dim myarray As String 

改成

 Dim myarray As Variant