Text Editing VBA

excelnewbie2018

New Member
Joined
Jan 16, 2018
Messages
8
Dear community,

I am pretty new to the world of VBA! I am currently working on an assignment and I would like to produce a regular report out of my analysis so that I can keep tracks of the changes. I would only like the report to look natural instead of being ckearly generated by a computer, therefore I would like to create a code picking a term from a pre-prepared list of words, so that the comment looks innovative every time.
I do not think that the function CHOOSE works in this case.

To be more precise the code I have created would be the following:
Code:
If output.Range("B2") < 20 Then
        amt_hours = Choose("part time", "seasonal work")

However, I am not sure that this is the right oath to follow. I would really appreciate if someone could help me with this.
Thanks in advance! :)
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hello and welcome.

This explains how the function works. You need to provide the index. Therefore if you want a random choice you will need to generate a random variable and use that as the choice...
 
Upvote 0
Here is an example using the Choose function:

Code:
Sub TestRandom()
    Dim iIndex As Integer, iLower As Integer, iUpper As Integer
    Dim sRandomResult As String
    
    
    iLower = 1
    iUpper = 3


    Randomize
    'GET RANDOM NUMBER BETWEEN iLower and iUpper
    iIndex = Int(iLower + Rnd() * (iUpper - iLower + 1))
    
    'use random number to select out of list
    sRandomResult = Choose(iIndex, "Choice1", "Choice2", "Choice3")
    
    MsgBox sRandomResult
    
End Sub
 
Upvote 0
Here is an example using the Choose function:

Code:
Sub TestRandom()
    Dim iIndex As Integer, iLower As Integer, iUpper As Integer
    Dim sRandomResult As String
    
    
    iLower = 1
    iUpper = 3


    Randomize
    'GET RANDOM NUMBER BETWEEN iLower and iUpper
    iIndex = Int(iLower + Rnd() * (iUpper - iLower + 1))
    
    'use random number to select out of list
    sRandomResult = Choose(iIndex, "Choice1", "Choice2", "Choice3")
    
    MsgBox sRandomResult
    
End Sub

That is exactly what I have just done! Thank you so much for your precious help.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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