'编写一个自定义函数 shc 让其自动获得当前工作簿的工作表个数
shc = Sheets.Count
'在工作表里 输入 “=shc()”就得到当前工作簿的工作表个数
'自定义函数一定要在模块中输入
End Function
Function Lianjie(mrg As Range, msr As String)
'做自定义函数 lianjie连接(数组参数,连接符参数)
Dim m As String
With Application
If mrg.Columns.Count > 1 Then
'当选的数组为一行内的数组(列数>1)时
m = Join(.Transpose(.Transpose(mrg)), msr)
'用Join函数把数组连接成字符串
'对于行的数组需要用Application.Transpose进行2次转换
ElseIf mrg.Columns.Count = 1 Then
m = Join(.Transpose(mrg), msr)
'因为一维数组都是横向的,对于列的数组需要进行1次转换
End If
Lianjie = m
End With
End Function
Function fenge(rng As Range, msr As String, x%)
'做自定义函数fenge(单元格参数,分隔符参数,第几个参数(数字))
arr = Split(rng, msr)
'用split函数把字符串(“要分隔的单元格”rng )拆分成数组成为arr数组
fenge = arr(x - 1)
'根据数值参数返回第n个数组(x-1 因为数组起始为0)
End Function
Function ticheng(a As Range)
Select Case a
Case Is > 20000
n = a * 0.03
Case Is > 10000
n = a * 0.02
Case Is >= 0
n = a * 0.01
Case Is < 0
n = 0
End Select
ticheng = n
End Function
Private Sub Workbook_BeforePrint(cancel As Boolean)
'打印前事件 “不允许打印”工作簿 放在 thisworkbook 的 workbook 里
MsgBox "不能打印"
cancel = True 'cancel = True 不能打印
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'工作表当前单元格事件 对工作表的指定列(前3列)不能输入
If Target.Column < 4 Then Range("d1").Select
End Sub