Add a sheet vba

Jessie20

New Member
Joined
Oct 19, 2022
Messages
9
Office Version
  1. 365
Platform
  1. MacOS
Hi, I would like my code to show on an additional sheet when I run it. When I try to run my code, my excel just bug. Can you help me please? Thanks

Sub Question4()
Dim mA(1 To 100, 1 To 100) As Integer
Dim i As Integer
Dim j As Integer

For i = 1 To 100
For j = 1 To 100
mA(i, j) = i - j
If i - j = 1 Or i - j = -1 Then
mA(i, j) = 1
Else
mA(i, j) = 0
End If
ActiveWorkbook.Sheets.Add.Cells(i, j) = mA(i, j)
Next j
Next i


End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Are you trying to create new sheets and populate cells on these new sheets all at the same time?
I don't know that you can populate the cells at the same time you add the new sheet.
I think you will need to do that in two steps; first create the sheet, then populate any cells in the new sheet that you want.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,821
Messages
6,121,755
Members
449,049
Latest member
excelknuckles

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