ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   loop over columns (https://www.excelbanter.com/excel-discussion-misc-queries/39447-loop-over-columns.html)

kizzie

loop over columns
 

Hello,

How do I write a for loop over columns? e.g. For k= A to AA ... is not
working...

thx in advance


--
kizzie
------------------------------------------------------------------------
kizzie's Profile: http://www.excelforum.com/member.php...o&userid=26092
View this thread: http://www.excelforum.com/showthread...hreadid=394203


Dave Peterson

for k = 1 to 27

or ...


with activesheet
for k = .range("a1").column to .range("aa1").column



======
If you're using .cells(), then it can accept either letters or numbers for the
column:

cells(1,3).value = "asdf"
is just as ok as:
cells(1,"C").value = "asdf"



kizzie wrote:

Hello,

How do I write a for loop over columns? e.g. For k= A to AA ... is not
working...

thx in advance

--
kizzie
------------------------------------------------------------------------
kizzie's Profile: http://www.excelforum.com/member.php...o&userid=26092
View this thread: http://www.excelforum.com/showthread...hreadid=394203


--

Dave Peterson

kizzie


thx

Cells(Nr).Value = Cells(Nr).Value + Cells(ActiveCell.Rows,
ActiveCell.Columns + 2).Value

Whats wrong with this code? I want to add the value the cell 2 columns
right of the active cell, to the cell named "Nr"

thx


--
kizzie
------------------------------------------------------------------------
kizzie's Profile: http://www.excelforum.com/member.php...o&userid=26092
View this thread: http://www.excelforum.com/showthread...hreadid=394203


Dave Peterson

Nr is a range name?

cells("Nr").value _
= cells("Nr").value + cells(activecell.row,activecell.column+2).value

or

cells("Nr").value _
= cells("Nr").value + activecell.offset(0,2).value



kizzie wrote:

thx

Cells(Nr).Value = Cells(Nr).Value + Cells(ActiveCell.Rows,
ActiveCell.Columns + 2).Value

Whats wrong with this code? I want to add the value the cell 2 columns
right of the active cell, to the cell named "Nr"

thx

--
kizzie
------------------------------------------------------------------------
kizzie's Profile: http://www.excelforum.com/member.php...o&userid=26092
View this thread: http://www.excelforum.com/showthread...hreadid=394203


--

Dave Peterson

Dave Peterson

Oops....if Nr is really a named cell, use this intead.

Range("Nr").value _
= range("Nr").value + cells(activecell.row,activecell.column+2).value

or

range("Nr").value _
= range("Nr").value + activecell.offset(0,2).value



Dave Peterson wrote:

Nr is a range name?

cells("Nr").value _
= cells("Nr").value + cells(activecell.row,activecell.column+2).value

or

cells("Nr").value _
= cells("Nr").value + activecell.offset(0,2).value

kizzie wrote:

thx

Cells(Nr).Value = Cells(Nr).Value + Cells(ActiveCell.Rows,
ActiveCell.Columns + 2).Value

Whats wrong with this code? I want to add the value the cell 2 columns
right of the active cell, to the cell named "Nr"

thx

--
kizzie
------------------------------------------------------------------------
kizzie's Profile: http://www.excelforum.com/member.php...o&userid=26092
View this thread: http://www.excelforum.com/showthread...hreadid=394203


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 06:00 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com