Private Sub cmdAdd_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = ActiveSheet
'find first empty row in sheet
iRow = .Range("A1").End(xlDown).Row + 1
我缺少什么,我的数据被覆盖了,因为它不会前进到下一个空行?
答案 0 :(得分:1)
这是让你开始的事情: <击> 撞击>
<击>Sub SheetPicker()
Dim msg As String
Dim sh As Worksheet
Dim V As Variant
msg = vbCrLf
For Each sh In Sheets
msg = msg & sh.Name & vbCrLf
Next sh
Do
V = Application.InputBox(prompt:="Please pick from:" & msg, Type:=2)
If V = False Then
Exit Sub
End If
If Exists(CStr(V)) Then
Sheets(V).Select
Exit Sub
End If
Loop
End Sub
Function Exists(s As String) As Boolean
Dim sh As Worksheet
Exists = False
For Each sh In Sheets
If sh.Name = s Then
Exists = True
Exit Function
End If
Next sh
End Function
击> <击> 撞击>
修改#1:强>
此版本可避免隐藏的工作表:
Sub SheetPicker()
Dim msg As String
Dim sh As Worksheet
Dim V As Variant
msg = vbCrLf
For Each sh In Sheets
If sh.Visible = xlSheetVisible Then
msg = msg & sh.Name & vbCrLf
End If
Next sh
Do
V = Application.InputBox(prompt:="Please pick from:" & msg, Type:=2)
If V = False Then
Exit Sub
End If
If Exists(CStr(V)) Then
Sheets(V).Select
Exit Sub
End If
Loop
End Sub
Function Exists(s As String) As Boolean
Dim sh As Worksheet
Exists = False
For Each sh In Sheets
If sh.Visible = xlSheetVisible Then
If sh.Name = s Then
Exists = True
Exit Function
End If
End If
Next sh
End Function