FOR i =

lecet444

Board Regular
Joined
May 18, 2011
Messages
91
what is the alternative if you are trying to use it for columns, i would like to fill columns across as oppose to rows down!!

thank You,
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
You can still use a For i = loop structure...


For i = 1 to 10
Cells(1,i).Value = i
Next i

that will put the numbers 1 through 10 in row 1 column A through J
 
Upvote 0
this is probably a very stupid question,
i have already used for i = 1 to 9

can i use for j
For j= 1 to 10
Cells(1,j).Value = j
Next j
 
Upvote 0
Sure, but when you start having multiple variables, you might give them descriptive names to help keep track of what each variable is for.
Like, MyCol and MyRow...

Code:
For MyRow = 1 To 10
    For MyCol = 1 To 5
        Cells(MyRow,MyCol).Value = MyRow & " - " & MyCol
    Next MyCol
Next MyRow
 
Upvote 0
You can name the variable whatever you want (just don't start with numbers, use special characters, or choose reserved words like function names, properties, etc).
It is always wise to declare your variables before using them, i.e.
Code:
Dim i as Integer
Dim j as Integer
...
 
Upvote 0
In addition to what Joe said,

It is also wise to put this at the top of your module.

Option Explicit

This forces you to declare your variables.
It also helps to prevent mistakes like Misspelling things (a major cause of many headaches)
 
Upvote 0
It is also wise to put this at the top of your module.

Option Explicit

This forces you to declare your variables.
An excellent suggestion. Really helps with debugging errors.
 
Upvote 0
thank you for your feedback. really helpful.

if I want to run them side by sid eg

Code:
Dim ccell As Integer
Dim i As Integer
Dim clast As Long
clast = bk3.Range("B" & bk2.Cells.Rows.Count).End(xlUp).Row
For i = 3 To clast

ccell = Sheets("raw data").Range("b" & i).Value
 

Worksheets("raw data").Range("c" & i).Select
ActiveCell.FormulaR1C1 = "='F:\Engineering\Michael\Excel\INVENTORY\PO\[" & ccell & ".xls]PO'!R33C19"
[COLOR=red]Worksheets("raw data").Range("d" & i).Select[/COLOR]
[COLOR=red]ActiveCell.FormulaR1C1 = _
        "=IF(ISNA(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[" & ccell & ".xls]PO'!R16C3:R30C3,MATCH(R1C4,'F:\Engineering\Michael\Excel\INVENTORY\PO\[" & ccell & ".xls]PO'!R16C4:R30C4,0))),"""",(INDEX('F:\Engineering\Michael\Excel\INVENTORY\PO\[" & ccell & ".xls]PO'!R16C3:R30C3,MATCH(R1C4,'F:\Engineering\Michael\Excel\INVENTORY\PO\[" & ccell & ".xls]PO'!R16C4:R30C4,0))))"
[/COLOR] Next i

how would i have that code (one in red) jump to the next column and then the next and so on since it has i in it, so it goes down. I want it to go down and across
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,292
Members
452,902
Latest member
Knuddeluff

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