VBA Convert Number To String

VBA Convert Number to String

VBA Convert Number To String, we use CStr data type conversion VBA function. The number can be integer, or any numeric value. In the following article let us see an example. And also see the step by step instructions to run VBA code in the visual basic editor(VBE) window. You can find link at the end of the session to know more about CStr VBA function.

Convert Number to String

Let us see an example VBA macro code how to convert number to string.

'VBA Convert Number to Function
Sub VBAF1_Convert_Number_to_Function()

    'Variable Declaration
    Dim iNum As Integer, sResult As String
    
    'Assign value to variable
    iNum = 100
    
    'Check given input value is number or not
    If IsNumeric(iNum) Then
        sResult = CStr(iNum)
        MsgBox sResult, vbInformation, "VBAF1"
    Else
        MsgBox "Enter valid number.", vbInformation, "VBAF1"
    End If

End Sub

Explanation: First we are checking given input value is numeric or not.To check we are using IsNumeric VBA function. This function is a VBA information function. Once we are done with checking, if it is numeric value then converting number to a string value. Run this code in debug mode. Stop at msgbox as shown in the following screen shot. Put cursor on iNum and then notice given input value has converted to string. It is in double quotes.

VBA Convert Number To String
VBA Convert Number To String

Instructions to Run VBA Macro Code or Procedure:

You can refer the following link for the step by step instructions.

Instructions to run VBA Macro Code

Other Useful Resources:

Click on the following links of the useful resources. These helps to learn and gain more knowledge.

VBA Tutorial VBA Functions List VBA Arrays VBA Text Files VBA Tables

VBA Editor Keyboard Shortcut Keys List VBA Interview Questions & Answers Blog

Leave a Comment