Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default How to iterate through columns?

I have a particular issue with columns.

I have 4 columns. I need to iterate through the 4 columns (say H - K).
The values in the columns are put there from a database record set.
The record set, therefore, has a row length that could be variable,
depending on the number of records.

how can I iterate through 1-4 columns or any columns with data and
select the data from the column and get it's address?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default How to iterate through columns?

You can adapt the following code to meet your needs:

Sub AAA()
Dim LastRow As Long
Dim ColNdx As Long
Dim RowNdx As Long
Dim V As Variant
Dim R As Range
Dim Addr As String

Const START_COL = 8 '<<<< CHANGE
Const START_ROW = 10 '<<<< CHANGE
LastRow = Cells(Rows.Count, START_COL).End(xlUp).Row

For RowNdx = START_ROW To LastRow
For ColNdx = START_COL To START_COL + 4
'''''''''''''''''''''''''
' set the range
'''''''''''''''''''''''''
Set R = Cells(RowNdx, ColNdx)
'''''''''''''''''''''''''
' get the address
'''''''''''''''''''''''''
Addr = R.Address
'''''''''''''''''''''''''
' get the value
'''''''''''''''''''''''''
V = R.Value
'''''''''''''''''''''''''
' do something with V
'''''''''''''''''''''''''
Debug.Print V
Next ColNdx
Next RowNdx
End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"axwack" wrote in message
...
I have a particular issue with columns.

I have 4 columns. I need to iterate through the 4 columns (say H - K).
The values in the columns are put there from a database record set.
The record set, therefore, has a row length that could be variable,
depending on the number of records.

how can I iterate through 1-4 columns or any columns with data and
select the data from the column and get it's address?


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
iterate columns to select certain cells Dale[_16_] Excel Programming 4 February 24th 06 05:48 PM
Iterate through a form RobEdgeler Excel Programming 2 September 17th 05 06:58 PM
Can't iterate thru a row with For peter Excel Programming 2 January 7th 05 04:46 AM
Iterate columns wired Excel Programming 9 November 14th 03 11:14 PM


All times are GMT +1. The time now is 05:02 PM.

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

About Us

"It's about Microsoft Excel"