2019-03-16 19:32阅读:328
打开excel-开发工具-Visual Basic-双击Sheet1(sheet1)-在右侧的代码区输入:
'如何在单击某个区域的单元格时判断该单元是否为空
'如果为空时,数值为所在列数 '如果不为空则输入空值 Private Sub Worksheet_SelectionChange(ByVal Target As Range) ''类似单击事件 If Target.Value = '' Then '如果单元格为空 Target.Value = '=Column()' '单元格变为所在列的列数 Else Target.Value = '' End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Application.Intersect([B1:F12], Target) Is Nothing Then '仅在B1:F12范围内起作用 If Target.Value = '' Then '如果单元格为空 Target.Value = '=Column()' '单元格变为所在列的列数 Else Target.Value = '' End If End If End Sub |
|
来自: yzjqrz > 《VB / VBA / ASP》