Help: Simple loop into entire column

tt.viquel

New Member
Joined
Apr 14, 2011
Messages
30
I need a simple loop that runs through column A2:A20 and display the results from each of the sets into AC2:AC29, then i need it to do the same with column B2:B20 and display in AD2:AD20.
Please please help me
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Welcome to the forums!

Why not enter =A2 in AC2, then copy it down and right?

Do you need this in VBA code as part of a larger code?
 
Upvote 0
Perhaps something like

Code:
Dim ColumnNumber as Long
Dim RowNumber as Long
Dim outPutValue as Double

For ColumnNumber = 1 to 2

    For RowNumber = 2 to 20
        outPutValue = Range("A1").Cells(RowNumber, ColumnNumber)
       
        Rem calculate outPutValue

        Range("AD1").Cells(RowNumber, ColumnNumber) = outPutValue
    Next RowNumber

Next ColumnNumber
 
Upvote 0
Thank you both but the reason why i didnt want to use the first approach was because in the cells one column contains sql queries that need to be executed and have the result displayed in the AC column that s why..but i try the 2nd appraoch and see if it works.

Thank you both
 
Upvote 0
Can i aks another quick question, because i want to understand why did you use
Code:
For ColumnNumber = 1 To 2
why up to 2 is it default or can i have it as any number. and also after
Code:
Next ColumnNumber
do i just add the new column detail and add more so on with all the columns i want to run.
 
Upvote 0
The upper bound of the loop can be set to any number you want.

That was a code snippet that would be put into a Sub. After the loops are done, carry on with processing the sheet until your
Code:
End Sub
 
Upvote 0
So if i use this approach:
Code:
Dim ColumnNumber As Long
Dim RowNumber As Long
Dim outPutValue As Double
For ColumnNumber = 1 To 2
    For RowNumber = 2 To 20
        outPutValue = Range("AE2").Cells(RowNumber, ColumnNumber)
        Range("AA2").Cells(RowNumber, ColumnNumber) = outPutValue
    Next RowNumber

For ColumnNuber = 1 To 2
For RowNumber = 2 To 20
outPutValue = Range("AF2").Cells(RowNumber, ColumnNumber)
Range("AB2").Cells(RowNumber, ColumnNumber) = outPutValue
Next RowNumber
For Column = 1 To 2
For RowNumber = 2 To 20
outPutValue = Range("AG2").Cells(RowNumber, ColumnNumber)
Range("AC2").Cells(RowNumber, ColumnNumber) = outPutValue
Next RowNumber

it should work as in is the structure ok or have i added too many or missed out some parameters ??
 
Upvote 0
That code has a bunch of For statements without the matching Next.

It looks like you are moving columns AE:AG to AA:AC for rows 2-20.
If thats what you are doing, no loop is necessary. One line is sufficient.
Code:
Range("AA2:AC20").Value = Range("AE2:AG2").Value

You need to loop only if you are going to be altering the values.
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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