excel2010中,sheet1中有按钮1,点击显示窗体form2,可以录入。把按钮放到sheet2中就不行了,截图如下:
PrivateSubCommandButton1_Click()DimiRow&,j%,arr(1To14),ih%ih=TextBox1.Value+1WithShee...
Private Sub CommandButton1_Click()
Dim iRow&, j%, arr(1 To 14), ih%
ih = TextBox1.Value + 1
With Sheet1
iRow = .Range("A65536").End(xlUp).Row + 1
For j = 1 To 14
arr(j) = Me.Controls("textbox" & j)
Me.Controls("textbox" & j) = ""
Next j
.Cells(iRow, 1).Resize(1, 14) = arr
.Cells(iRow, 1).Resize(1, 15).Borders.LineStyle = 1
End With
TextBox1.Value = ih
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = Date
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox8_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub UserForm_Initialize()
TextBox1 = Sheet1.Range("A65536").End(xlUp).Row - 2
End Sub 展开
Dim iRow&, j%, arr(1 To 14), ih%
ih = TextBox1.Value + 1
With Sheet1
iRow = .Range("A65536").End(xlUp).Row + 1
For j = 1 To 14
arr(j) = Me.Controls("textbox" & j)
Me.Controls("textbox" & j) = ""
Next j
.Cells(iRow, 1).Resize(1, 14) = arr
.Cells(iRow, 1).Resize(1, 15).Borders.LineStyle = 1
End With
TextBox1.Value = ih
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub TextBox1_Change()
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Value = Date
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox8_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub TextBox9_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
Private Sub UserForm_Initialize()
TextBox1 = Sheet1.Range("A65536").End(xlUp).Row - 2
End Sub 展开
1个回答
推荐于2016-11-16
展开全部
用录制宏实现工资条的生成
录制两段宏:
1.第一个宏的录制与运行:选择sheet2的A1单元格,单击“工具-宏-录制新宏”,设快捷键为ctrl+j,点“确定”,出现一个录制宏的工具条,确保该工具条上的第二个按钮“相对引用”为选中状态。然后点击sheet1工作表标签回到sheet1中选择放置工资表列字段的那一整行也就是标题行)
2.第二个宏的录制与运行:选择sheet2的A2单元格,单击“工具-宏-录制新宏”,设快捷键为ctrl+k,点“确定”后,同样确保“相对引用”按钮为选中状态。然后转到sheet1中选择放置工资表第一条记录的那一整行(也就是除标题行之外的第一条记录行)按ctrl+c复制,再回到sheet2,按ctrl+v粘贴,再选择A5单元格,再次转到sheet1选择第二条记录行进行复制,并再次回到sheet2粘贴,再将光标定位到A8单元格,单击“停止录制”按钮,完成录制。这时,按住ctrl键不放,不停地按k键即可实现快速将各条不同的记录行有序地复制到其它行。
录制两段宏:
1.第一个宏的录制与运行:选择sheet2的A1单元格,单击“工具-宏-录制新宏”,设快捷键为ctrl+j,点“确定”,出现一个录制宏的工具条,确保该工具条上的第二个按钮“相对引用”为选中状态。然后点击sheet1工作表标签回到sheet1中选择放置工资表列字段的那一整行也就是标题行)
2.第二个宏的录制与运行:选择sheet2的A2单元格,单击“工具-宏-录制新宏”,设快捷键为ctrl+k,点“确定”后,同样确保“相对引用”按钮为选中状态。然后转到sheet1中选择放置工资表第一条记录的那一整行(也就是除标题行之外的第一条记录行)按ctrl+c复制,再回到sheet2,按ctrl+v粘贴,再选择A5单元格,再次转到sheet1选择第二条记录行进行复制,并再次回到sheet2粘贴,再将光标定位到A8单元格,单击“停止录制”按钮,完成录制。这时,按住ctrl键不放,不停地按k键即可实现快速将各条不同的记录行有序地复制到其它行。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询