Dynamically update for sheet name

Danny54

Active Member
Joined
Jul 3, 2019
Messages
295
Office Version
  1. 365
Platform
  1. Windows
Good Afternoon

I have a vb statement in my excel macro that I need to dynamically change the workbook sheet just created as the macro loops.

the current statement is
[Sheet1!A1:J1].Resize(N).Value2 = S

after that i have a line that adds a new sheet to the workbook
Sheets.Add After:=Sheets(Sheets.Count)

Then loop back to the statement
[Sheet1!A1:J1].Resize(N).Value2 = S

how would I code to use the sheet just created?


Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
?

workflow goes like this
[Sheet1!A1:J1].Resize(N).Value2 = S <- this statement dumps the array S into Sheet3
Sheets.Add After:=Sheets(Sheets.Count) <- I then create a new sheet
Erase S() <- erase the array
ReDim S(1 To Rows.Count, 9) <- ReDim the array
loop here <- loop thru code to reload the array again

Now I need to dump the new array data into the newly created worksheet which would be Sheet2

The original statement as show above
"[Sheet1!A1:J1].Resize(N).Value2 = S" to this
"[Sheet2!A1:J1].Resize(N).Value2 = S" then i loop again creating a new sheet Sheet3, change this statement again and loop.

Thanks
 
Upvote 0
Another hint, when you add a sheet it becomes the active sheet.
 
Upvote 0
At minimum, it sounds like you could use something like:

VBA Code:
With Sheets.Add(After:=Sheets(Sheets.Count))
    .Name = "SomeNewName"
    .Range("A1:J1").Resize(N).Value2 = S
End With

But it sounds like you want to create multiple new sheets? Do you need to "reload" S, or will S be different for each sheet?

Perhaps you could provide more detail?
 
Upvote 0
Solution
No, johnnyL. Got pulled into something else for a moment. Yes, you helped

Thanks to all that helped.
 
Upvote 0
Ok. I was just going to suggest:

Instead of:
Start Loop
Dump array to sheet
Add a new sheet
Erase array
Redim array
Load array
Loop back to beginning

Try:
Start Loop
Dump array to sheet
Redim array
Load array
Add a new sheet
Loop back to beginning

That way you can dump to the active sheet and not have to worry about what the name of it is ;)
 
Upvote 0

Forum statistics

Threads
1,224,812
Messages
6,181,088
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top