1

I'm looking for way around getting multiple values set to one variable declared as String. Following codes might give you a glimpse of what I'm looking for

Dim Name as string
Name = value1 or value2 or value3
If range("A1"). Value = Name then
    Activecell.entirecolumn.delete
End If
2
  • Can't you use array ? Commented Aug 27, 2015 at 8:20
  • You can, for example, add a , between your var then use a loop to check if the word between the , is the work you're looking for Commented Aug 27, 2015 at 8:25

1 Answer 1

1
    Dim Name As String
    Dim value1 As String, value2 As String, value3 As String

    Name = value1 & "," & value2 & "," & value3

    If InStr(Name, Range("A1")) <> 0 Then
        ActiveCell.EntireColumn.Delete
    End If

The program loop through A1 to see if one of the value match. If it does, Instr will return the position in Name where they match. So, simply tells your program that is Instr isn't equal to 0 to delete what you want

Sign up to request clarification or add additional context in comments.

10 Comments

Mark it to say this helped and solved your problem, it will help ppl if they envounter the same problem
Question : Do I really have to mention limit like Name(3), can't I just say Name() and it will let me add as long as I want?
Of course you can, but if you can know how many obj there will be then put it. Or you can use Dim Name(1 to 150) to say there can be 1 to 150 object. Or just Name()
If you are sure Name will always have string, you can declare it as Dim Name() as string
Thanks, I think I'd just go with Name() so that I don't have to count them and just add a value whenever required..
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.