Home>Blogs>VBA>RandBetweenText Formula in Excel
RandBetweenText Function
VBA

RandBetweenText Formula in Excel

In this article, we have created a user defined function RandBetweenText Formula in Excel. This function returns random text from the selected range. You can use this function to distribute the text randomly or to create the dummy data set.

Here we have create a dummy data using RandBetweenText Formula –

RandBetweenText Formula
RandBetweenText Formula

Watch the step by step video tutorial:

Below is the VBA code for this UDF-

Option Explicit

Function RandBetweenText(Input_Value As Range) As String

Application.Volatile

Dim rng As Range
Dim Random_Values As String

For Each rng In Input_Value
  If Random_Values = "" Then
     Random_Values = rng.Value
  Else
     Random_Values = Random_Values & "," & rng.Value
  End If
Next

Dim arr As Variant
arr = Split(Random_Values, ",")

Dim n As Integer
n = UBound(arr)

RandBetweenText = arr(Application.WorksheetFunction.RandBetween(0, n))

End Function

Visit our YouTube channel to learn step-by-step video tutorials

Youtube.com/@PKAnExcelExpert

Click here to download this practice file.

PK
Meet PK, the founder of PK-AnExcelExpert.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your Excel skills to the next level!
https://www.pk-anexcelexpert.com