Dim sth as string

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
923
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
 

Some videos you may like

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
I don't see why not..


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

Message Box would show Apple28745
 

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
923
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.
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061
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)
 

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061

ADVERTISEMENT

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
 

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
923
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:

Jonmo1

MrExcel MVP
Joined
Oct 12, 2006
Messages
44,061

ADVERTISEMENT

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
 

Vanda_a

Well-known Member
Joined
Oct 29, 2012
Messages
923
You're welcome.

Hello again

This mark " * " covers all strings. not only number but also text.

Ex: My sheet name is INVDDD. This Like & "*" still read it. How can I have it read only numeric?
 

Watch MrExcel Video

Forum statistics

Threads
1,123,494
Messages
5,602,004
Members
414,490
Latest member
Rip181

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
Top