Dim sth as string

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
934
Dear all

May I know if it is possible that I can set sth like this?

dim AA as string

AA = "Apple" & number(any number)

Thank you very much
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I don't see why not..


Code:
Dim AA As String
AA = "Apple" & 28745
MsgBox AA

Message Box would show Apple28745
 
Upvote 0
I don't see why not..


Code:
Dim AA As String
AA = "Apple" & 28745
MsgBox AA

Message Box would show Apple28745

No.. I meant the number can be any number but not specific.

I got many sheets to save as PDF. All the start with same letter(Apple231) or (Orange555) so if I can set AA "Apple" & any num, then I can make my code work. Now am struggling with this problem.
 
Upvote 0
You can replace the 28745 with any number you like.
How should the number be chosen?

This will choose it randomly..
AA = "Apple" & Application.Randbetween(1,1000)
 
Upvote 0
Maybe you mean something like this

Code:
Sub test()
Dim AA As String, ws As Worksheet
AA = "Apple"
For Each ws In Worksheets
    If ws.Name Like AA & "*" Then
        MsgBox ws.Name
    End If
Next ws
End Sub
 
Upvote 0
One more please.

Above post was my own one that I am try to learn.

This one I got help from other
Code:
Sub PDFSAVEE()
    Dim fPath As String
    fPath = "C:\User\Vanda\Desktop\"
    Dim ws As Worksheet
    For Each ws In Worksheets
        Select Case ws.Name
            Case "INV", "Reim", "DN"
                ws.ExportAsFixedFormat xlTypePDF, Filename:=fPath & "MyPDF_" & ws.Name & ".pdf"
            Case Else
                'do nothing
        End Select
    Next ws
End Sub

Like * "*" still work on it?
Case Like "INV" * "*"
 
Last edited:
Upvote 0
OK, now we can see the scope of what you're doing..

Try
Code:
Sub test()
Dim ws As Worksheet
Dim INVname(1 To 3) As Variant, i As Long

INVname(1) = "INV"
INVname(2) = "Reim"
INVname(3) = "DN"

For Each ws In Worksheets
    For i = LBound(INVname) To UBound(INVname)
        If ws.Name Like INVname(i) & "*" Then
            MsgBox ws.Name
        End If
    Next i
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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