按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!
2。form 中有 textbox 设名称为 input1
以上若未设则error
我在做自定义菜单欲仿 EXCEL 菜单用横线分隔各菜单项目
解答:下面是我用到的代码:
Set mymenubar = mandBars。ActiveMenuBar
Set newmenu1 = mymenubar。Controls。Add(Type:=msoControlPopup; _
Temporary:=True)
newmenu1。Caption = 〃文件制作 (&M)〃
newmenu1。BeginGroup = True '这就是你要的白色横线
用 VBA 函数算出行数值
解答:如在 A 列有数据
Sub pd()
401
…………………………………………………………Page 402……………………………………………………………
a = 1
Do Until Cells(a; 1) = 〃〃
a = a + 1
Loop
行数 = a 1
End Sub
解答 2:假如数据在A 列,试试这个,中间有空单元格也没关系,
Right(Sheet1。Columns(1)。SpecialCells(xlCellTypeConstants; xlNumbers +
xlTextValues)。Address; 1)
再问解答 2:你整怎么复杂,是什么意思哟?
解答:研究研下面宏你就会明白了
Sub kkk()
ActiveSheet。Cells(2; 1) = 〃Text1〃
ActiveSheet。Cells(4; 1) = 2
ActiveSheet。Cells(5; 1) = 〃Text2〃
ActiveSheet。Cells(8; 1) = 3
MsgBox ActiveSheet。Columns(1)。SpecialCells(xlCellTypeConstants; _
xlNumbers)。Address
MsgBox ActiveSheet。Columns(1)。SpecialCells(xlCellTypeConstants; _
xlTextValues)。Address
MsgBox ActiveSheet。Columns(1)。SpecialCells(xlCellTypeConstants; _
xlNumbers + xlTextValues)。Address
End Sub
在 VBA 中判断单元格区域内是否为空值
解答:用循环语句
Sub kg()
Dim mycell As Range
For Each mycell In Range(〃a1:e9〃)
If mycell = 〃〃 Then mycell = 1000
Next mycell
End Sub
Sub sumrange()
Dim mycell As Range
For Each mycell In Range(〃a1:e9〃)
If mycell 〃〃 Then myresult = mycell+myresult
Next mycell
End Sub
excel 中如何设定光标输入到某个单元格后回车自动换行
解答:Option Explicit
Const ColumnOfTheCell2BeReturn As Integer = 5 '到第 5 列换行
'指定单元格中按回车键自动换行
402
…………………………………………………………Page 403……………………………………………………………
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static LastRow As Integer
Dim R%; C%
R = Target。Row:
C = Target。Column
If Application。MoveAfterReturnDirection = …4161 Then '按回车光标右移
If C = ColumnOfTheCell2BeReturn + 1 Then Cells(R + 1; 1)。Select
End If
If Application。MoveAfterReturnDirection = …4121 Then '按回车光标下移
If C = ColumnOfTheCell2BeReturn And (R LastRow = 1) Then Cells(R; 1)。Select
End If
LastRow = R
End Sub
修改上面解答:Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Static LastColumn As Integer
C = Target。Column
Select Case Target。Column
Case 5
Application。MoveAfterReturn = False 'STOP
'Cells(Target。Row + 1; 1)。Select '第一格
Case Is 《 5
Application。MoveAfterReturn = True
Application。MoveAfterReturnDirection = xlToRight '右移
Case Is 》 5
Application。MoveAfterReturn = True
Application。MoveAfterReturnDirection = xlDown '下移
End Select
If C = 5 And C = LastColumn Then Cells(Target。Row + 1; 1)。Select
LastColumn = C
End Sub
带编号的(000001 ………999999)在打印时实现自动编号
解答:Sub 序号打印 ()
Dim lsh As Integer
lsh = 0
Do While lsh