Taking the first letter from multiple words in a cell + adding a random number

jamesdor45

New Member
Joined
Feb 25, 2013
Messages
21
Hi Guys!

A couple of days I posted a message and you manage to solve my problem! I have another question, which I hope you can help a newbie like me.

I need to create a sequence of letters + numbers that will according to this layout:

Take the first letter from each word showing in cell A1 + take the first letter from each word showing in cell B1. Then I need the system to generate a random number between 1-1000 that will show at the end. So it should show like this:

A1 – fat cat eating
B1 – dog is drinking

I then need to add a random numbers (between 1-1000) to the end. So what I will get in cell C1 is this:

C1 - fcedid876

Can you guys please help me with the formula? I tired playing and searching it all over but without any luck.

Thanks again,
Jerry
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
If the number of words is not known and you want the random number to remain constant, you will need a UDF.
Code:
Function FLandRand(rng As Range)
For Each cl In rng
    n = 1
    For i = 1 To Len(cl)
        If Mid(cl, i, 1) = " " Or i = Len(cl) Then
            FLandRand = FLandRand & Mid(cl, n, 1)
            n = i + 1
        End If
    Next i
Next
FLandRand = FLandRand & Round(Rnd * 1000, 0)
End Function
Now you can use it in C1:
=FLandRand(A1:B1)
 
Last edited:
Upvote 0
Hi iyyi,

Thank you so much for the quick follow up and it does work perfect. I didn’t mention that I have a number of numbers of lines in-between. So the actual example should be that I would get the letters from cell A1 and cell D1 (but not the ones from B or C). For example, right now I get the following:

A1 – fat cat eating
B1 - banana
C1 – water bottle
D1 – dog is drinking

So what I get on the designated cell is this – fcebwbdid475. So can you please help so it will only include A and D (and not everything in between).

Thanks so much! TODA!

Regards,
Jerry
 
Upvote 0
Hi iyyi,

Thank you so much for the quick follow up and it does work perfect. I didn’t mention that I have a number of numbers of lines in-between. So the actual example should be that I would get the letters from cell A1 and cell D1 (but not the ones from B or C). For example, right now I get the following:

A1 – fat cat eating
B1 - banana
C1 – water bottle
D1 – dog is drinking

So what I get on the designated cell is this – fcebwbdid475. So can you please help so it will only include A and D (and not everything in between).

Thanks so much! TODA!

Regards,
Jerry
The next code will let you input 1,2 or 3 ranges.
Code:
Function FLandRand(rng1 As Range, Optional rng2 As Range, Optional rng3 As Range)
If rng2 Is Nothing And rng3 Is Nothing Then
    Set rng = rng1
ElseIf rng3 Is Nothing Then
    Set rng = Application.Union(rng1, rng2)
Else
  Set rng = Application.Union(rng1, rng2, rng3)
End If


For Each cl In rng
    n = 1
    For i = 1 To Len(cl)
        If Mid(cl, i, 1) = " " Or i = Len(cl) Then
            FLandRand = FLandRand & Mid(cl, n, 1)
            n = i + 1
        End If
    Next i
Next
FLandRand = FLandRand & Round(Rnd * 1000, 0)
End Function
so in your case it would be:
=FLandRand(A1,D1)

Notice that =FLandRand(A1:B1,C1,D1:E1) is valid too
 
Upvote 0
Hi

For a variable number of single cell arguments, also:

Code:
Function FirstLetters(ParamArray vRngs()) As String
Dim vRng As Variant, v As Variant
Dim s As String

For Each vRng In vRngs
    For Each v In Split(vRng.Value)
        s = s & Left(v, 1)
    Next v
Next vRng
FirstLetters= s & Application.WorksheetFunction.RandBetween(0, 999)
End Function

For ex.:

=FirststLetters(A1,C2,F4,B5)
 
Upvote 0

Forum statistics

Threads
1,215,206
Messages
6,123,639
Members
449,111
Latest member
ghennedy

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