VBA nested for loop

anneau

New Member
Joined
Nov 28, 2020
Messages
2
Office Version
  1. 365
Platform
  1. Windows
SKILL DRILL
  1. Create a nested for loop that puts a 1 into the cells of all columns A through J, and rows 1 through 10 (e.g., cells A1 - A10, B1 - B10, and so forth).
the code I used for the first is this:

Sub AllStocksAnalysis()
Worksheets("All Stocks Analysis").Activate

Range("A1").Value = "All Stocks (2018)"

'Create a header row
Cells(3, 1).Value = "Ticker"
Cells(3, 2).Value = "TotalDailyVolume"
Cells(3, 3).Value = "Return"

For i = 1 To 10
For j = 1 To 10
Cells(i, j).Value = 1

Next j

Next i

End Sub
  1. Modify the nested for loop to put the sum of the row number and column number into each cell.
  2. Modify the nested for loop again to fill in any rectangular block of cells for m columns and n rows.

I'm not exactly sure what to write to put the sum of the row number and column number and to fill in any rectangular block of cells.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

mrshl9898

Well-known Member
Joined
Feb 6, 2012
Messages
1,791
I'm not exactly sure what to write to put the sum of the row number and column number and to fill in any rectangular block of cells.

VBA Code:
Cells(i, j).Value = i + j
 

Watch MrExcel Video

Forum statistics

Threads
1,130,181
Messages
5,640,640
Members
417,159
Latest member
Mayozero

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
Top