ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   enum - howto make columns correspond to numbers? (https://www.excelbanter.com/excel-programming/396750-enum-howto-make-columns-correspond-numbers.html)

royend

enum - howto make columns correspond to numbers?
 
Hi.
I need to reference my columns by number - e.g. a variable X = 4
should be a reference to the column D.

My first though was to use enum, where I set the value of each column
to their corresponding number, like this:
public enum IChar
A = 1
B = 2
C = 3
D = 4
....
end enum

Now, if my X = 4, I need to find the correct character according to my
enum:
IChar.D = 4

But is there some predefined function which will help me find the
correct enum?
Something like this findEnum(X), e.g. findEnum(4) = D.

I really believe this will be my solution as I need to select
programatically (VB) a set of columns according to a user-input in my
worksheet.

Looking forward to your help.


Dave Peterson

enum - howto make columns correspond to numbers?
 
You don't need to.

You could use:

You could use:

dim X as long
x = 4
with activesheet
msgbox .columns(x).address
'or
msgbox .cells(1,x).entirecolumn.address
end with

..cells(w,z) is very forgiving.
W has to be a number (row)
but z can be a letter or a number.

I'm not sure what you mean by the last part.

royend wrote:

Hi.
I need to reference my columns by number - e.g. a variable X = 4
should be a reference to the column D.

My first though was to use enum, where I set the value of each column
to their corresponding number, like this:
public enum IChar
A = 1
B = 2
C = 3
D = 4
...
end enum

Now, if my X = 4, I need to find the correct character according to my
enum:
IChar.D = 4

But is there some predefined function which will help me find the
correct enum?
Something like this findEnum(X), e.g. findEnum(4) = D.

I really believe this will be my solution as I need to select
programatically (VB) a set of columns according to a user-input in my
worksheet.

Looking forward to your help.


--

Dave Peterson

royend

enum - howto make columns correspond to numbers?
 
On 1 Sep, 23:05, Dave Peterson wrote:
You don't need to.

You could use:

You could use:

dim X as long
x = 4
with activesheet
msgbox .columns(x).address
'or
msgbox .cells(1,x).entirecolumn.address
end with

.cells(w,z) is very forgiving.
W has to be a number (row)
but z can be a letter or a number.

I'm not sure what you mean by the last part.





royend wrote:

Hi.
I need to reference my columns by number - e.g. a variable X = 4
should be a reference to the column D.


My first though was to use enum, where I set the value of each column
to their corresponding number, like this:
public enum IChar
A = 1
B = 2
C = 3
D = 4
...
end enum


Now, if my X = 4, I need to find the correct character according to my
enum:
IChar.D = 4


But is there some predefined function which will help me find the
correct enum?
Something like this findEnum(X), e.g. findEnum(4) = D.


I really believe this will be my solution as I need to select
programatically (VB) a set of columns according to a user-input in my
worksheet.


Looking forward to your help.


--

Dave Peterson- Skjul sitert tekst -

- Vis sitert tekst -


Thanks!

royend



All times are GMT +1. The time now is 10:48 PM.

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