感谢大家的帮助并指出正确的方向。这是我最终使用的:
Sub Expand_Array_On_New_Sheet
' First check that new sheet name doesn't already exist, and create sheet
Sheet_name_to_create = Sheet10.Range("B1").Value
If WorksheetExists2(Sheet10.Range("B1")) Then
MsgBox "Sheet name already exists"
Exit Sub
Else
Sheets.Add After:=Sheets(1)
ActiveSheet.Name = Sheet_name_to_create
End If
' Copy array data to new sheet
Worksheets("Lookup").Range("A11:B250").Copy
Range("A101").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False
Application.CutCopyMode = False
' Expand Array Data into Columns and do some formatting
Range("B101:B350").Select
Selection.TextToColumns Destination:=Range("C101"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False, OtherChar _
:=",", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1)), TrailingMinusNumbers:=True
Range("C100").Select
ActiveCell.FormulaR1C1 = "=R[-98]C[-1]-19"
Range("D100").Select
ActiveCell.FormulaR1C1 = "=RC[-1]+1"
Range("D100").Select
Selection.AutoFill Destination:=Range("D100:V100"), Type:=xlFillDefault
Range("W100").Select
ActiveCell.FormulaR1C1 = "Current"
Range("C100:W100").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
Selection.Font.Bold = True
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("B1").Select
End Sub
它似乎运作良好。我遇到的挥之不去的问题是,如果数据集少于 21 个条目(大多数是 21 个,但不是全部),最后一列数据最终会出现在 T 或 V 列或其他地方。我需要最后一个条目始终位于 W 列中,并向后填充。我可能需要将其作为一个单独的问题进行搜索。
再次感谢大家的帮助!