I am trying to write a VBA function to write an array to a worksheet to help me debug problems.
I have tried all the variants shown after 'Add worksheet and none of them will add a new worksheet to the workbook. I have not even gotten to the part about writing out the array. So simple and so frustrating that there must be a simple answer!
Thank you for your help.
Sub Array2Range(arrx As Variant)
Dim NumRow As Long, NumCol As Long
Dim WriteRange As Range
NumRow = NumElements(arrx, 1)
NumCol = NumElements(arrx, 2)
'Add worksheet
'Set sh = ThisWorkbook.Worksheets.Add
'sh.Name = "MySheet"
'Worksheets.Add(After:=Sheets(Sheets.Count)).Name = "MySheet"
'Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "MySheet"
'Worksheets.Add , Worksheets(Worksheets.Count)
'ActiveSheet.Name = "Array"
'Write array to new worksheet
Set WriteRange = Range(ActiveSheet.Cells(1, 1), ActiveSheet.Cells(NumRow, NumCol))
WriteRange.Value = arrx
End Sub
Bookmarks