Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using Range & Cell

I wish to create a macro that will require processing several columns in an
incremental way.
As far as I can tell, I have 2 options :-
1) Use, for example, Cells(x,colnum) with something like an increment
counter [e.g. colnum = colnum+1] but then I need to know how to translate,
say, column CW into a number.
2) Use, for example, Range("CW1") but then how do I increment from CW to CX
to CY etc.


Help appreciated & many thanks

Jack


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Using Range & Cell

Hi Jack,

Perhaps try something like:

'=============
Public Sub Tester()
Dim col As Range

For Each col In Range("C:H").Columns
'do something, e.g,:
MsgBox col.Address
Next col
End Sub
'<<=============


---
Regards,
Norman


"Jack" wrote in message
...
I wish to create a macro that will require processing several columns in an
incremental way.
As far as I can tell, I have 2 options :-
1) Use, for example, Cells(x,colnum) with something like an increment
counter [e.g. colnum = colnum+1] but then I need to know how to translate,
say, column CW into a number.
2) Use, for example, Range("CW1") but then how do I increment from CW to
CX to CY etc.


Help appreciated & many thanks

Jack



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Using Range & Cell

See below for answers to your two specific questions. The
best way would probably depend on how you specify the
"several columns". One approach might be:

Dim topCell as Range, colNo as integer
For Each topCell in Range ("CW1:DD1")
colNo = topCell.Column
' do stuff with the column
Next

Andrew

Jack wrote:
I wish to create a macro that will require processing several columns in an
incremental way.
As far as I can tell, I have 2 options :-
1) Use, for example, Cells(x,colnum) with something like an increment
counter [e.g. colnum = colnum+1] but then I need to know how to translate,
say, column CW into a number.


Range("CW1").Column gives you the column number.

2) Use, for example, Range("CW1") but then how do I increment from CW to CX
to CY etc.


Dim myRange as Range
Set myRange = Range("CW1")
'' do stuff with CW1
Set myRange = Range("CW1").Offset(0,1) ' sets myRange to CX1



Help appreciated & many thanks

Jack


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Range & Cell


Jack Wrote:
I wish to create a macro that will require processing several columns in
an
incremental way.
As far as I can tell, I have 2 options :-
1) Use, for example, Cells(x,colnum) with something like an
increment
counter [e.g. colnum = colnum+1] but then I need to know how to
translate,
say, column CW into a number.
2) Use, for example, Range("CW1") but then how do I increment from CW
to CX
to CY etc.


Help appreciated & many thanks

Jack

Hope this will get you started

Code:
--------------------

Dim y As Long, i As Long
y = Range("CW1").Column
For i = 0 To 10
Cells(x, y + i) = i
Next
' Using Offset
With Range("CW" & x)
For i = 0 To 10
.Offset(, i) = i
Next
End With
--------------------


--
jindon
------------------------------------------------------------------------
jindon's Profile: http://www.excelforum.com/member.php...o&userid=13135
View this thread: http://www.excelforum.com/showthread...hreadid=551315

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
RANGE EXCEL copy cell that meets criteria in a range confused Excel Worksheet Functions 3 March 27th 08 01:41 PM
Referencing a named range based upon Range name entry in cell Barb Reinhardt Excel Worksheet Functions 14 June 20th 07 07:19 PM
Selecting range in list of range names depending on a cell informa Courreges Excel Discussion (Misc queries) 2 June 19th 06 10:59 AM
Change cell colour for a cell or range within a predefined range Martin[_21_] Excel Programming 2 May 23rd 05 06:16 PM
Range.Find returns cell outside of range when range set to single cell Frank Jones Excel Programming 12 June 10th 04 04:22 AM


All times are GMT +1. The time now is 07:08 AM.

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"