Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Walking Through Cells Using a Loop

BEGINNER'S QUESTION:
I am creating an application in Excel that will use a block of cells for
display - 9 rows and 9 columns - A1-A9, B1-B9, ..., I1-I9. In several
places, I would like to look at or write to each cell using a FOR loop in VBA:

FOR row=1 to 9
FOR col=1 TO 9
write to cell at (row, col)
NEXT col
NEXT row

How do I create cell references dynamically in a loop based on "row" and
"col"? Is there a better way to programatically cycle through a series of
cells other than using FOR loops?

Thank you.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Walking Through Cells Using a Loop, Cells()

Try ActiveWindow.ActiveSheet.Cells(row, col) or just Cells(row,col).

"Negnog" wrote in message
...

How do I create cell references dynamically in a loop based on "row" and
"col"? Is there a better way to programatically cycle through a series of
cells other than using FOR loops?

Thank you.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Walking Through Cells Using a Loop

Use

Cells(row,col).Value = 123

As an aside, 'row' is a reserved word in Excel/VBA, and good
programming practice would preclude it from being used as a
variable name. Use 'RowNum' or something similar instead.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Negnog" wrote in message
...
BEGINNER'S QUESTION:
I am creating an application in Excel that will use a block of
cells for
display - 9 rows and 9 columns - A1-A9, B1-B9, ..., I1-I9. In
several
places, I would like to look at or write to each cell using a
FOR loop in VBA:

FOR row=1 to 9
FOR col=1 TO 9
write to cell at (row, col)
NEXT col
NEXT row

How do I create cell references dynamically in a loop based on
"row" and
"col"? Is there a better way to programatically cycle through
a series of
cells other than using FOR loops?

Thank you.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 222
Default Walking Through Cells Using a Loop

Cells(Row, col) = value to write to cell

"Negnog" wrote:

BEGINNER'S QUESTION:
I am creating an application in Excel that will use a block of cells for
display - 9 rows and 9 columns - A1-A9, B1-B9, ..., I1-I9. In several
places, I would like to look at or write to each cell using a FOR loop in VBA:

FOR row=1 to 9
FOR col=1 TO 9
write to cell at (row, col)
NEXT col
NEXT row

How do I create cell references dynamically in a loop based on "row" and
"col"? Is there a better way to programatically cycle through a series of
cells other than using FOR loops?

Thank you.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Walking Through Cells Using a Loop, For Loops

For loops are good. You might look at For Each of a Range object, example:
Dim c
For Each c In ActiveWindow.RangeSelection
Next c

"Negnog" wrote in message
...

"col"? Is there a better way to programatically cycle through a series of
cells other than using FOR loops?


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
START UP FORMS FOR DOG WALKING BUSINESS (HELP ) FATHIYYAH Excel Discussion (Misc queries) 1 May 28th 08 10:23 PM
walking menu Grams Excel Worksheet Functions 3 September 30th 07 10:57 PM
Help - loop through cells in a range that are not together (several different cells as Target) Marie J-son[_5_] Excel Programming 4 April 3rd 05 09:54 PM
Loop through cells Sheeny[_2_] Excel Programming 7 May 6th 04 12:02 AM
VBA loop cells Adrie Rahanra Excel Programming 1 September 30th 03 10:22 AM


All times are GMT +1. The time now is 10:32 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"