Excel / VBA CStr function

The CStr function is used to convert a value to a string.

What is CStr function in VBA

The CStr function is used to convert a value to a string.

It takes an expression as an argument i.e.

CStr( expression )

The examples below show the usage of CStr function.

An example to convert an Integer to String by CStr

We have an integer type variable and assigned it a value. Then we used CStr function to convert it to a string.

Convert a Single variable (with a decimal number) to String

Similarly, you may convert a decimal number to string by CStr function. The following VBA program shows:

Converting date to string example

Converting cell values to String example

A date variable value is converted to string and displayed in a message box by CStr function:



Using Excel cell numbers and writing in another cell after conversion

We will use the A2 and A3 cells’ value (that contain numbers) in the CStr function and write the converted value to the B2 and B3 cells.



Writing different values to cells after conversion by CStr

In this example, we have a number, a decimal number, a string, text with a number, and date in A2 to A5 cells.

We used a for loop to iterate through all cells and assign the respective values to B cells after conversion by CStr function.

See the code and output: