H + 1).Value + B1 > 0 Then
Cells(I2, H + 2).Value = Cells(I3, H + 2) / Cells(I3, H + 1) * B1 + Cells(I2, H + 2).Value
MsgBox (Cells(I2, H + 2).Value), , "总数"
Cells(I2, H) = sj.Text
Cells(I2, H + 3) = fhks.Value
Cells(I2, H + 1) = sl.Value
Cells(I2 + 1, H + 1).Formula = "=SUM(R[" & -I2 + 2 & "]C:R[-1]C)"
Cells(I2 + 1, H + 2).Formula = "=SUM(R[" & -I2 + 2 & "]C:R[-1]C)"
Unload Me
Exit Sub
Else
B3 = B2 - Cells(I3, H + 1).Value - B1
MsgBox (B3), , "沉淀数量"
MsgBox (Cells(I2, H + 2).Value)
MsgBox (Cells(I3, H + 2) / Cells(I3, H + 1) * B3)
Cells(I2, H + 2).Value = Cells(I3, H + 2) / Cells(I3, H + 1) * B3 + Cells(I2, H + 2).Value
MsgBox (Cells(I2, H + 2).Value), , "过程金额"
B2 = Cells(I3, H + 1).Value + B1
B1 = B2
I3 = I3 - 1
MsgBox (B1), , "差额数量"
GoTo LINE4:
End If
Else
B1 = B1 + Cells(I3, H + 1).Value
I3 = I3 - 1
GoTo LINE4:
End If
使用了循环语句
使用了b1 b2 b3 作为数量的传递.
简单测试通过.
一个加密系统
在打开EXCEL时,先运行我的加密窗口(用VBA编写的LOCK.frm),现在请问,如何在当关闭-加密窗口(lock.frm)时,自动关闭EXCEL??我曾经见过其它EXCEL模块有此功能,但不知如何编写的。
解答:********ThisWorkbook program *********
Private Sub Workbook_Open()
UserForm1.Show
End Sub
*********** UserForm1 program *********
Private Sub CommandButton1_Click()
UserForm1.Hide
If UCase(input1) <> "ULOCK" Then 'input1>>textbox
MsgBox "密码错误"
ActiveWindow.Close
End If
MsgBox "欢迎使用本系统......."
End Sub
在不同工作表里位置相同的单元格里相同的公式,根据工作表名称引用不同的单元格
解答:如果工作表的名称做的有规律就比较简单,可以用变量生成序号,然后合成工作表名称,比如:
i=5
j="sheets"+ctsr(i)
m=j.cells(2,1).value
更改i 的值就能引用不同工作表了。
如果没有规律,可以求工作表的序号,进而得到工作表的名称,然后如何引用就很类似了。
快速撤销工作表保护
有一工作表,在其中的几列中有计算公式,比如B、F、K列等,且其中有一列公式使用的函数为HYPERLINK(),直接点击该单元格时会打开一个网页。当我要在工作表中进行chā入行cāo作时,如何快速完成如下工作:1:撤销工作表保护;2、将所有公式复制到新chā入行中;3、进行工作表保护。
如果使用宏该如何设计?
解答:1。在你的宏前先取消保护
ActiveSheet.Unprotect ("1234")
此例假设密码为 1234
执行完宏再次保护工作表
ActiveSheet.Protect Password:="1234"
此例假设密码 1234.
2:你的第1,3问如楼上所说,或写个过程:
Sub sSheetProtect(Protect As Boolean)
With ActiveSheet
If .ProtectContents = True Then
.Unprotect Password:="password"
End If
If Protect = True Then
If .ProtectContents = False Then
.Protect Password:="password", DrawingObjects:=True, Contents:=True, Scenarios:=True
End If
End If
End With
End Sub
第2个问:
Rows("4:4").Insert Shift:=xlDown
Rows("3:3").Copy
Rows("4:4").PasteSpecial Paste:=xlFormulas
关于加密窗口的问题
问题一:关于加密窗口的问题!上次请教了一个关闭EXCEL函数的问题!现在又发现一个问题:即在VBA的FRM窗口右上方的“X”如果去掉?因为它关闭了我的加密窗口就不起作用?或者如果按“X”的时候,自动关闭EXCEL就行,如何?问题二,我每次经过加密窗口后进入工作表,总是被隐藏了,用什么函数把隐藏的自动打开?
解答:1、Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode <> 1 Then Cancel = 1
UserForm1.Caption = "The Close box won't work! Clickcom!"
End Sub
2、Sub dd()
For i = 1 To Worksheets.Count
Sheets(i).Visible = True
Next i
End Sub
加密窗口为何总是出现424出错信息
*********** UserForm1 program *********
Private Sub CommandButton1_Click()
UserForm1.Hide /// 这里总是出错424
If UCase(input1) <> "ULOCK" Then 'input1>>textbox
MsgBox "密码错误"
ActiveWindow.Close
End If
MsgBox "欢迎使用本纟统......."
End Sub
解答:1.你要先自订Form,Form的名称为UserForm1
2.form中有textbox 设名称为input1
以上若未设则error
我在做自定义菜单yù仿EXCEL菜单用横线分隔各菜单项目
解答:下面是我用到的代码:
Set mcomnubar = CommandBars.ActiveMenuBar
Set necomnu1 = mcomnubar.Controls.Add(Type:=msoControlPopup, _
Temporary:=True)
necomnu1.Caption = "文件制作(&M)"
necomnu1.BeginGroup = True '这就是你要的白色横线
用VBA函数算出行数值
解答:如在A列有数据
Sub pd()
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, _