使用vba语言如何插入一个随机且字体和字号都随机的数
发布网友
发布时间:2022-10-18 20:10
我来回答
共2个回答
热心网友
时间:2023-12-19 02:40
以下代码在选中单元格生成1~100的随机数,字号从6~52号,字体有9种。
要想更多随机情况,自己修改代码中相关数据。详见附件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Ra As Range
For Each Ra In Target
Randomize
Ra = Int(Rnd() * 100 + 1)
Ra.Font.Name = Choose(Int(Rnd() * 9 + 1), "仿宋_GB2312", "Arial Unicode MS", "宋体", "黑体", "幼圆", "隶书", "Batang", "Dotum", "MS PGothic")
Ra.Font.Size = Int(48 * Rnd() + 6)
Next
End Sub
热心网友
时间:2023-12-19 02:40
sub aa(R As Range)
Dim c As Double
Dim zt() As String
Dim zh() As Integer
ReDim zt(3)
zt(1) = "黑体"
zt(2) = "宋体"
zt(3) = "华文行楷"
'...
ReDim zh(3)
zh(1) = 6
zh(2) = 8
zh(3) = 10
'...
'使c的变化范围在1-3之间
c = Int(Rnd() * (3 - 1) + 1)
R.Font.Name = zt(c)
R.Font.Size = zh(c)
End sub
放到chang事件里面去