Fromlostdays1
New Member
- Joined
- Jul 18, 2022
- Messages
- 14
- Office Version
- 365
- Platform
- Windows
Intro: I have a lot of data in columns in Excel. I can already use:
Select Case Range ("A1").value to give me the value of A1 and use that to do various things with. For instance, if I wanted to return a message based on the data in A1:
Problem / Question:
What I need to do is somehow define the column as a variable, I think, so that I can somehow define the column on the fly somewhere else, but leave the row number in tact. I would prefer to be able to somehow define the column as text in a defined cell I could just fill in on the fly.
This is what I have so far, but I don't think I'm even close to getting it right. In this example I'm trying to define a column in cell A2 and then have the code search A2, then run in the specificied column always on row 20:
Thanks for any advice!
Select Case Range ("A1").value to give me the value of A1 and use that to do various things with. For instance, if I wanted to return a message based on the data in A1:
Code:
Select Case Range ("A1").value
Case ""
Case "Yes"
MsgBox "This is true"
Case "No"
MsgBox "This is not true!"
Problem / Question:
What I need to do is somehow define the column as a variable, I think, so that I can somehow define the column on the fly somewhere else, but leave the row number in tact. I would prefer to be able to somehow define the column as text in a defined cell I could just fill in on the fly.
This is what I have so far, but I don't think I'm even close to getting it right. In this example I'm trying to define a column in cell A2 and then have the code search A2, then run in the specificied column always on row 20:
VBA Code:
Dim ColNum As Integer
'Define Column as a variable
ColNum = Range("A2").Value
'Tell Excel where to look for which Column I want the code to run in, in this case I was hoping I could write a letter in box A2 and that letter would define which column the code would run in
Select Case Range(ColNum & "20").Value
'This is where I'm really lost. How do I tell the Select case to look for the variable column letter I defined in A2 but also always use row 20?
Case ""
Case "Yes"
MsgBox "This is true"
Case "No"
MsgBox "This is not true!"
Thanks for any advice!