I am trying to:
In this case I am export many (possibly hundreds) of worksheets. Instead of adding the worksheet with Worksheets.Add or Sheets.Add I would like to create a worksheet object (before it gets added to the collection) and add my information to it first. That way, when I'm done I can just add all the worksheet objects I have created to the worksheets collection. I tried to write some code for what I think that might look like (I know .Add doesn't take that syntax, and .Cells isn't working):
I am happy to say more as to why I want to do this this way (performance reasons) if that helps solve the question.
- Take the input data from a range, all at once (and loading it up in Arrays and Dictionaries)
- do my business logic
- export only what I need (worksheet objects), ALL at once (saving going back and forth between the logic and the 'view' - in this case the worksheet)
In this case I am export many (possibly hundreds) of worksheets. Instead of adding the worksheet with Worksheets.Add or Sheets.Add I would like to create a worksheet object (before it gets added to the collection) and add my information to it first. That way, when I'm done I can just add all the worksheet objects I have created to the worksheets collection. I tried to write some code for what I think that might look like (I know .Add doesn't take that syntax, and .Cells isn't working):
Code:
Public Sub exampleSub()
Dim worksheetInMemory As New Worksheet
worksheetInMemory.Cells(1, 1) = "test info"
Worksheets.Add (worksheetInMemory)
End Sub
I am happy to say more as to why I want to do this this way (performance reasons) if that helps solve the question.