filling cells with random char

lezawang

Well-known Member
Joined
Mar 27, 2016
Messages
1,805
Office Version
  1. 2016
Platform
  1. Windows
Hi
I wrote the code below to fill cells with random char. It does not work. I also have another question. Why Char() is not part of Application.Worksheetfunction?
I thought all excel functions that you can find in Fx, you can find then under Worksheetfunction. But that is not the case. I found Application.Chr function and I tried to use it in my code blow. Thank you so much.

Code:
Sub selection_fill2()
    'fill selection with random number
    Dim xcell As Range
    Dim x As Integer
    For Each xcell In Selection
        x = Application.WorksheetFunction.RandBetween(1, 56)
        xcell.Value = x
        xcell.vaule = Application.Chr(x)
    Next xcell
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hey,

you want something like this?

Code:
Sub selection_fill2()
    'fill selection with random number
    Dim xcell As Range
    Dim x As Integer
    For Each xcell In Selection
        x = Application.WorksheetFunction.RandBetween(1, 56)
        xcell.Value = Chr(x)
    Next xcell
End Sub

Char is Chr in VBA and is not so much an application but a transformation
 
Last edited:
Upvote 0
Thank you for your help. I appreciate it. I am a bit confused now. When I need to call a VBA function with Application.FunctionName
and when I need to call them with just FunctionName?

According to this link https://www.techonthenet.com/excel/formulas/index_vba.php these functions can be called using Application.FunctionName
or that is what I thought?

Thank you.
 
Upvote 0
I don't think there is that much difference really, maybe some slight differences with error handling(?) as far as I am aware both are fine to use? Interesting question though
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,147
Members
452,615
Latest member
bogeys2birdies

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