ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   multiply text and number (https://www.excelbanter.com/excel-programming/407363-multiply-text-number.html)

Lucy

multiply text and number
 
Hi there, I'm writing a UDF and trying to multiply text and number. (Answer
will show in text)

Function Pallet(MyNum)
Dim i As Integer
i = MyNum Mod 20
Dim j As Integer
j = Fix(MyNum / 20)

if i = 9 and i <= 12 then "L" should appear (j-1) times
Let's say MyNum = 72
So, i = MyNum Mod 20 = 12
And j = Fix(MyNum / 20) = 3

I want the answer shows letter "L" appear (j-1) times, which is 2 times
like this : LL [in text format]

Is it possible?

Since outside this UDF, I count the total occurences of letter "L" in a
range. Therefore, i prefer answer in here shows "LL" instead of "2 L"

Thank you.

joel

multiply text and number
 
Function Pallet(MyNum) As String
Pallet = String(Int(MyNum / 20) - 1, "L")
End Function

"Lucy" wrote:

Hi there, I'm writing a UDF and trying to multiply text and number. (Answer
will show in text)

Function Pallet(MyNum)
Dim i As Integer
i = MyNum Mod 20
Dim j As Integer
j = Fix(MyNum / 20)

if i = 9 and i <= 12 then "L" should appear (j-1) times
Let's say MyNum = 72
So, i = MyNum Mod 20 = 12
And j = Fix(MyNum / 20) = 3

I want the answer shows letter "L" appear (j-1) times, which is 2 times
like this : LL [in text format]

Is it possible?

Since outside this UDF, I count the total occurences of letter "L" in a
range. Therefore, i prefer answer in here shows "LL" instead of "2 L"

Thank you.


Lucy

multiply text and number
 
Thanks Joel, it works perfect!

"Joel" wrote:

Function Pallet(MyNum) As String
Pallet = String(Int(MyNum / 20) - 1, "L")
End Function

"Lucy" wrote:

Hi there, I'm writing a UDF and trying to multiply text and number. (Answer
will show in text)

Function Pallet(MyNum)
Dim i As Integer
i = MyNum Mod 20
Dim j As Integer
j = Fix(MyNum / 20)

if i = 9 and i <= 12 then "L" should appear (j-1) times
Let's say MyNum = 72
So, i = MyNum Mod 20 = 12
And j = Fix(MyNum / 20) = 3

I want the answer shows letter "L" appear (j-1) times, which is 2 times
like this : LL [in text format]

Is it possible?

Since outside this UDF, I count the total occurences of letter "L" in a
range. Therefore, i prefer answer in here shows "LL" instead of "2 L"

Thank you.



All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com