作者:静静 | 来源:互联网 | 2023-05-19 12:20
it's my first time posting on Stack Overflow. I am trying to use VBA to get it to create a new worksheet based on a cell value in sheet 1. But if the sheet already exists I need it to open that sheet instead. I'm having difficulty with this as I don't actually know the name of the sheet. I thought I could do this if I create another sheet where it stores the names of projects, using a counter. It shows me I have run-time error 91. This is the code I currently have:
这是我第一次在Stack Overflow上发帖。我正在尝试使用VBA让它基于表1中的单元格值创建一个新的工作表。但是如果这个表单已经存在,我需要它来打开这个表单。我有困难,因为我不知道这张纸的名字。我想我可以这样做,如果我创建另一个表,它存储项目的名称,使用一个计数器。它显示我有运行时错误91。这是我目前的代码:
Public Sub DailyReport()
Dim project As Range
project = Worksheets("Target Flow").Range("B3")
Dim i As Integer
i = 1
If Worksheets("Target Flow").Range("B3") <>
Worksheets("Projects").Cells(1000, 1).Value Then
Worksheets("Target Flow").Range("B3").Select
Selection.Copy
Worksheets("Projects").Activate
Cells(i, 1).Select
ActiveSheet.Paste
Dim WS As Worksheet
Set WS = Sheets.Add(After:=Sheets(Worksheets.Count))
WS.Name = project.Value
i = i + 1
Else
Worksheets("Target Flow").Activate
Worksheets(ActiveSheet.Range("B3").Value).Activate
End If
End Sub
If anyone could guide me in the right direction, I'd be grateful!!
如果有人能指引我正确的方向,我将感激不尽!
1 个解决方案