我想生成包含“_S”的所有值的新工作表:
当用户点击“生成页面”时,会创建两个新工作表(一个工作表标题为“Folder22_S”,另一个工作表标题为“Folder3_S”
第二次,我希望从模型生成新的工作表(不生成空工作表)
我的问题是:怎么做?我不知道如何找到包含“_S”的所有值并获取单元格值(Folder22_S和Folder3_S)?
我的伪VBA代码:
Sub generate()
'Array contains all values *_S'
Dim AllValuesContains_S As Variant
AllValuesContains_S = Array("Folder22_S", "Folder3_S", ...)
For Each item As String In AllValuesContains_S
Sheets.Add.Name = item
Next
End Sub
答案 0 :(得分:0)
我假设您要搜索的范围是A2:C7。将代码的这一部分调整为您需要的任何范围。
Sub New_Wksht()
Dim SearchRange as Range, c as Range
Dim sht as Worksheet
With ThiwWorkbook
Set SearchRange = .Sheets("Your Sheet Name").Range("A2:C7") 'Change sheet name and range to be what you need
For Each c in SearchRange
If Right(c.Value,2) = "_S" Then
Set sht = .Sheets.Add
sht.Name = c.Value
End If
Next C
End With
End Sub