[英]VBA: Name Sheet in Array
I have one cell with all sheet name write in this way: "Sheet1", "Sheet2", "Sheet3".我有一个单元格,所有工作表名称都是这样写的:“Sheet1”、“Sheet2”、“Sheet3”。 So I insert this value in single variable SheetNames as String.所以我将此值作为字符串插入到单个变量 SheetNames 中。
Now, I need to get single sheet name and insert.现在,我需要获取单个工作表名称并插入。 My code is:我的代码是:
varSheets = Array(FogliArray)
'varSheets = Array("Other", "Research", "IT")
lngShtCnt = 0
On Error Resume Next
For Each varSheet In varSheets
With wkbSource.Worksheets(varSheet)
If I use varSheets = Array("Other", "Research", "IT") all work correctly.如果我使用 varSheets = Array("Other", "Research", "IT") 一切正常。 But if I use varSheets = Array(FogliArray) where FogliArray is variable that contains all sheet name ("Other", "Research", "IT") not works.但是,如果我使用 varSheets = Array(FogliArray) 其中 FogliArray 是包含所有工作表名称(“其他”、“研究”、“IT”)的变量,则不起作用。
Please, can you help me?拜托,你能帮我吗? Many thanks, Andrea.非常感谢,安德里亚。
Use Split
to return an array of the worksheet names, Replace
the quotes, and Trim$
the spaces, something like the following:使用Split
返回工作表名称的数组, Replace
引号,并Trim$
空格,如下所示:
Sub Test()
Dim FogliList As String
FogliList = Sheet1.Range("A1").Value
FogliList = Replace(FogliList, """", "") ' no quotes
Dim FogliArray
FogliArray = Split(FogliList, ",")
Dim i As Long
For i = LBound(FogliArray) To UBound(FogliArray)
Dim FoglioName As String
FoglioName = Trim$(FogliArray(i))
With wkbSource.Worksheets(FoglioName)
' Do whatever you wanted to do
End With
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.