What are the available ways to create Nested Loops in VBA?

excelos

Active Member
Joined
Sep 25, 2011
Messages
376
Office Version
  1. 365
Platform
  1. Windows
Hello

I want to create this nested loop:

For Each cell In Range("a1:a10")
Cell.value = 1*(For i = 0 to 10 next i)
Next cell

Any idea how it could be structured?

Also are there any other forms/types of nested Loops and what are the possible structures?

Thanks!
 

excelos

Active Member
Joined
Sep 25, 2011
Messages
376
Office Version
  1. 365
Platform
  1. Windows
Thanks, where can I find the documentation for the Cells(i, 1).Value please? Particularly the Cells(i, 1).
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,632
Office Version
  1. 365
Platform
  1. Windows
Just search the net for "Cells(i, 1).Value", plenty of sites come up. ;)
 

excelos

Active Member
Joined
Sep 25, 2011
Messages
376
Office Version
  1. 365
Platform
  1. Windows
I actually think it is mentioned in: Cell Object

By the way, I think:
Cells(i, 1).Value = (i + 4)*100
should be:
Cell(i, 1).Value = (i + 4)*100

Do you agree?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,632
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Why are you linking to documentation for Word?
 

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
14,050
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
  2. Mobile
Try the 2 codes below in Excel (see fluff's previous post), and tell us what happens
Documentation link

VBA Code:
Sub FillSequence()
  Dim i As Long

  For i = 1 To 10
    Cell(i, 1).Value = (i + 4) * 100
  Next i
End Sub

VBA Code:
Sub FillSequence()
  Dim i As Long

  For i = 1 To 10
    Cells(i, 1).Value = (i + 4) * 100
  Next i
End Sub
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
36,976
Office Version
  1. 2016
Platform
  1. Windows
And then, of course, you don't always need a loop :devilish:...
VBA Code:
Sub FillSequence()
  [A1:A10] = [100*ROW(5:14)]
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,735
Messages
5,638,057
Members
417,001
Latest member
MSteel

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