ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   String with Cell Reference (https://www.excelbanter.com/excel-programming/393945-string-cell-reference.html)

LarryP

String with Cell Reference
 
I have a procedure that has to deal with a sequence of columns that grows
from week to week; i.e., this week I'm working with columns A thru AJ, next
week it'll be A thru AK. At one point in the code I need a string
representation of the first cell in each column, e.g., "A1", "B1", etc. I
dealt with that initially by hardcoding an array to hold all the strings, but
I'm sure there must be a property I can iterate through to get the first-cell
references for whatever column I'm dealing with -- on the first pass give me
"A1", on the second give me "B1", etc. Can someone please help me with that
property name and/or bit of code?

Bernie Deitrick

String with Cell Reference
 
Larry,

Let's say that you have a ColumnCount variable

Sub TryNow()
Dim ColumnCount As Integer
Dim i As Integer

ColumnCount = 2

For i = 1 To ColumnCount
MsgBox Cells(1, i).Address(False, False)
Next i
End Sub


But there isn't any reason I can think of that would reguire a cell address in your code.... post
your code for further assistance ....

HTH,
Bernie
MS Excel MVP


"LarryP" wrote in message
...
I have a procedure that has to deal with a sequence of columns that grows
from week to week; i.e., this week I'm working with columns A thru AJ, next
week it'll be A thru AK. At one point in the code I need a string
representation of the first cell in each column, e.g., "A1", "B1", etc. I
dealt with that initially by hardcoding an array to hold all the strings, but
I'm sure there must be a property I can iterate through to get the first-cell
references for whatever column I'm dealing with -- on the first pass give me
"A1", on the second give me "B1", etc. Can someone please help me with that
property name and/or bit of code?




LarryP

String with Cell Reference
 
You can stand down, Bernie; the .ADDRESS reference you provided works fine,
got rid of the array and several string variables.

"Bernie Deitrick" wrote:

Larry,

Let's say that you have a ColumnCount variable

Sub TryNow()
Dim ColumnCount As Integer
Dim i As Integer

ColumnCount = 2

For i = 1 To ColumnCount
MsgBox Cells(1, i).Address(False, False)
Next i
End Sub


But there isn't any reason I can think of that would reguire a cell address in your code.... post
your code for further assistance ....

HTH,
Bernie
MS Excel MVP


"LarryP" wrote in message
...
I have a procedure that has to deal with a sequence of columns that grows
from week to week; i.e., this week I'm working with columns A thru AJ, next
week it'll be A thru AK. At one point in the code I need a string
representation of the first cell in each column, e.g., "A1", "B1", etc. I
dealt with that initially by hardcoding an array to hold all the strings, but
I'm sure there must be a property I can iterate through to get the first-cell
references for whatever column I'm dealing with -- on the first pass give me
"A1", on the second give me "B1", etc. Can someone please help me with that
property name and/or bit of code?






All times are GMT +1. The time now is 07:17 PM.

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