Declare one string with multiple variables

mhdakhtar8

New Member
Joined
Feb 4, 2013
Messages
36
Hi,

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
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
You don't need the Name variable ... You can just use this :
Code:
With Range("A1")
    If .Value = value1 Or .Value = value2 Or .Value = value3 Then
        ActiveCell.EntireColumn.Delete
    End If
End With

If you really need the Name string then if the variables value1,value2 and value3 contain strings then you could maybe use something along thes lines :
Code:
    Dim Name As String
    Name = Chr(0) + CStr(value1) + Chr(0) + CStr(value2) + Chr(0) + CStr(value3)

    On Error Resume Next
        With WorksheetFunction
            Name = UCase((.Index(Split(Name, Chr(0)), 1, .Match(CStr(Range("A1").Value), Split(Name, Chr(0))))))
        End With
    On Error GoTo 0

    If UCase(((CStr(Range("a1").Value)))) = Name Then
        ActiveCell.EntireColumn.Delete
    End If
 
Last edited:
Upvote 0
Here's what I'm using. but It's giving me Compile error for sname.Length. can you check?

Code:
Sub Generate_Producitvity_Report()
Dim OW As Workbook, ws As Worksheet, sname() As String, i As Integer
sname = Array("COS REJECT", "APPROVAL SENT", "Pending Client Response", "Awaiting Four-Eye Check", "Awaiting RDS Approval", "SHEET6", "SHEET1")
Set OW = ActiveWorkbook
For Each ws In ThisWorkbook.Worksheets
ws.Select
With ws
    [COLOR="#FF0000"]For i = 0 To sname.Length[/COLOR]
        If ws.Name <> sname(i) Then
        MsgBox sname(i) & " sheet not found"
        End If
    Next i
End With
Next ws
End Sub
 
Upvote 0
Try this :
Code:
Sub Generate_Producitvity_Report()
    Dim OW As Workbook, sname() As Variant, i As Integer
    sname = Array("COS REJECT", "APPROVAL SENT", "Pending Client Response", "Awaiting Four-Eye Check", "Awaiting RDS Approval", "SHEET6", "SHEET1")
    Set OW = ActiveWorkbook [B][COLOR=#008000]' <---- I think should be ThisWorkbook[/COLOR][/B]
    For i = 1 To OW.Worksheets.Count
        If InStr(1, Join(sname, Chr(0)), OW.Worksheets(i).Name, vbTextCompare) = 0 Then
            MsgBox OW.Worksheets(i).Name & " sheet not found"
        End If
    Next
End Sub
 
Upvote 0
You could also try this :
Code:
Sub Generate_Producitvity_Report()
    Dim OW As Workbook, ws As Worksheet, sname() As Variant, i As Integer
    sname = Array("COS REJECT", "APPROVAL SENT", "Pending Client Response", "Awaiting Four-Eye Check", "Awaiting RDS Approval", "SHEET6", "SHEET1")
    Set OW = ActiveWorkbook[B][COLOR=#008000] ' <---- I think should be ThisWorkbook[/COLOR][/B]
    For i = 0 To UBound(sname)
        On Error Resume Next
            Set ws = OW.Worksheets(sname(i))
            If ws Is Nothing Then
                MsgBox sname(i) & " sheet not found"
            End If
        On Error GoTo 0
    Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,038
Messages
6,128,450
Members
449,453
Latest member
jayeshw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top