我有一个 prevSheet()
功能在我的Excel工作表中。每当我将模板表复制并粘贴到新工作表中时,该功能都可以正常工作。后来我创造了 Addworksheets()
通过VBA功能,将模板表复制到新工作表中,重命名为&锁定它。从那时起 prevSheet()
功能不更新。每次我必须选择细胞和细胞按Enter键以通过计算选项设置更新它 Automatic
。
有人可以为此提供任何帮助吗?
这是我的addworksheet()函数:
Sub AddWorksheet() Application.Volatile
Dim i As Integer
Dim ws1 As Worksheet
If ThisWorkbook.ProtectStructure = False Then
Dim dateString As String, TheDate As Date Dim valid As Boolean: valid
= True
Do dateString = InputBox("Enter the first date of the month for which you want to prepare the sheet", "Enter The Date", Day(Now()) & "/" & Month(Now()) & "/" & Year(Now()))
If dateString = "" Then
MsgBox "You cancelled the action of creating new sheets. If you want to create new sheets for the month, it is manndatory to enter the date to detect the month and number of days of the month"
Exit Sub
Else
If IsDate(dateString) Then
TheDate = DateValue(dateString)
valid = True
Else
MsgBox "Invalid date"
valid = False
End If
End If
Loop Until valid = True
Dim mon As Integer
Dim yea As Integer
Dim days As Integer
mon = Month(TheDate)
yea = Year(TheDate)
days = Day(Application.WorksheetFunction.EoMonth(TheDate, 0))
Dim date1 As Date date1 = DateValue("1-" + mon + 1 & "-" & yea)
For i = 1 To 31
'# if to check if sheets already exists If Not sheetExists(32 - i) Then Set ws1 = Worksheets.Add(After:=Worksheets("DEBTORS"))
If 32 - i <= days Then Worksheets("TEMPLATE").Cells.Copy ws1.Cells(1, 1) End If
ws1.NAME = 32 - i
If i = 31 Then Worksheets("1").Range("$f$44").Value = date1 End If
ws1.Protect 32 - i, True, True End If ' # end of if that checks if sheet already exisits
Next
Else MsgBox "Please Remove Protection on your workbook structure to add sheets" & Chr(10) & "Review Tab => Protect Workbook" End If
End Sub
Function sheetExists(sheetToFind As String) As Boolean
sheetExists = False
For Each Sheet In Worksheets
If sheetToFind = Sheet.NAME Then
sheetExists = True
Exit Function
End If
Next Sheet End Function
这是我的prevsheet()函数:
Function PrevSheet(RCELL As Range)
'Application.Volatile
Dim i As Integer
Dim s As String
i = RCELL.Cells(1).Parent.Index
s = RCELL.Cells(1).Parent.NAME
If s = "1" Then
PrevSheet = 0
Else
PrevSheet = ThisWorkbook.Sheets(i - 1).Range(RCELL.Address)
End If
End Function
显示您的代码,因为它现在只能猜测。
—
Hannu
亲爱的Hannu,请检查,我已经更新了这个问题
—
Siva Prasad