Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Cells(i, "B") not working

Hi All,
I am using 2002 and have the following problem.

The following piece of code works perfectly:

'=== Calculate "comma delimited" =============================
With Range("AC12:AC" & lc)
For i = 1 To rn
..Cells(i) = _
..Cells(i, -26) & "," & _
..Cells(i, -25) & "," & _
..Cells(i, -24) & "," & _
..Cells(i, -23) & "," & _
..Cells(i, -22) & "," & _
..Cells(i, -21) & "," & _
..Cells(i, -20) & "," & _
..Cells(i, -19)
Next i
End With

Column -26 is column "B" and
Column -25 is column "C" etc...

So, I am given to understand that the following should work too:

'=== Calculate "comma delimited" =============================
With Range("AC12:AC" & lc)
For i = 1 To rn
..Cells(i) = _
..Cells(i, "B") & "," & _
..Cells(i, "C") & "," & _
..Cells(i, "D") & "," & _
..Cells(i, "E") & "," & _
..Cells(i, "F") & "," & _
..Cells(i, "G") & "," & _
..Cells(i, "H") & "," & _
..Cells(i, "I")
Next i
End With

But it doesn't and it would make life really simple if it did.

Any suggestions and comments would be greatly appreciated.

Geoff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 414
Default Cells(i, "B") not working

Your problem stems from the fact that you are referencing the cells
within the With Range("AC12:AC" & lc)...End With block. This means that
when you refer to .cells(i,"B") you are actually refering to the second
column from the point of view of your range i.e column AB.

So one option is to keep the code using the .cells(i,-26) structure or
remove the With...End With and use something like:
For i = 12 To rn + 11
Cells(i, 29) = _
Cells(i, "B") & "," & _
Cells(i, "C") & "," & _
Cells(i, "D") & "," & _
Cells(i, "E") & "," & _
Cells(i, "F") & "," & _
Cells(i, "G") & "," & _
Cells(i, "H") & "," & _
Cells(i, "I")
Next i

Hope this helps
Rowan

wrote:
Hi All,
I am using 2002 and have the following problem.

The following piece of code works perfectly:

'=== Calculate "comma delimited" =============================
With Range("AC12:AC" & lc)
For i = 1 To rn
.Cells(i) = _
.Cells(i, -26) & "," & _
.Cells(i, -25) & "," & _
.Cells(i, -24) & "," & _
.Cells(i, -23) & "," & _
.Cells(i, -22) & "," & _
.Cells(i, -21) & "," & _
.Cells(i, -20) & "," & _
.Cells(i, -19)
Next i
End With

Column -26 is column "B" and
Column -25 is column "C" etc...

So, I am given to understand that the following should work too:

'=== Calculate "comma delimited" =============================
With Range("AC12:AC" & lc)
For i = 1 To rn
.Cells(i) = _
.Cells(i, "B") & "," & _
.Cells(i, "C") & "," & _
.Cells(i, "D") & "," & _
.Cells(i, "E") & "," & _
.Cells(i, "F") & "," & _
.Cells(i, "G") & "," & _
.Cells(i, "H") & "," & _
.Cells(i, "I")
Next i
End With

But it doesn't and it would make life really simple if it did.

Any suggestions and comments would be greatly appreciated.

Geoff

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Cells(i, "B") not working


Create range names for each of the columns
select a cxolumn
Insert Name Define ...

- - Mark

PS See my excel stuff at:
http://www.geocities.com/excelmarksway

"You might find something if you look in the right place"

" wrote:

Hi All,
I am using 2002 and have the following problem.

The following piece of code works perfectly:

'=== Calculate "comma delimited" =============================
With Range("AC12:AC" & lc)
For i = 1 To rn
..Cells(i) = _
..Cells(i, -26) & "," & _
..Cells(i, -25) & "," & _
..Cells(i, -24) & "," & _
..Cells(i, -23) & "," & _
..Cells(i, -22) & "," & _
..Cells(i, -21) & "," & _
..Cells(i, -20) & "," & _
..Cells(i, -19)
Next i
End With

Column -26 is column "B" and
Column -25 is column "C" etc...

So, I am given to understand that the following should work too:

'=== Calculate "comma delimited" =============================
With Range("AC12:AC" & lc)
For i = 1 To rn
..Cells(i) = _
..Cells(i, "B") & "," & _
..Cells(i, "C") & "," & _
..Cells(i, "D") & "," & _
..Cells(i, "E") & "," & _
..Cells(i, "F") & "," & _
..Cells(i, "G") & "," & _
..Cells(i, "H") & "," & _
..Cells(i, "I")
Next i
End With

But it doesn't and it would make life really simple if it did.

Any suggestions and comments would be greatly appreciated.

Geoff


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default Cells(i, "B") not working

Thanks guys. That was a real help and is much appreciated.

BTW Mark.... I am in Sydney - perhaps a coffee sometime?

Geoff

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
how can I disable "cutting cells" and "drag and drop "in excel ? mwoody Excel Worksheet Functions 4 August 25th 08 03:53 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
Check if cells contain the word "Thailand", return "TRUE" ali Excel Worksheet Functions 7 September 14th 07 09:53 AM
Working out age from "Day" "Month" "Year" timmyc Excel Worksheet Functions 4 February 5th 06 03:07 PM
Using "Cells" to write "Range("A:A,H:H").Select" Trip Ives[_2_] Excel Programming 3 June 5th 04 03:13 PM


All times are GMT +1. The time now is 09:44 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"