根据名称列表命名工作表 [英] Name worksheets based on a list of Names
本文介绍了根据名称列表命名工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据范围(运行)中的名称,从范围(F4)中将名称新创建的工作表命名为lastrow。
I am trying to Name new created worksheets based on list of names in sheets("Run") from range ("F4") to lastrow.
我的问题:宏只是创建一个新的工作表,而不是根据名称的数量创建新的工作表列表。请参阅下面的代码:
My problem: The macro is only creating one new worksheet, instead of creating new worksheets based on the number of names in the list. Please see my code below:
Sub new_1()
Dim RCount As Integer
Dim n As Integer
Dim test As Worksheet
Sheets("Security Distribution").Copy After:=Sheets(Sheets.Count)
Set test = ActiveSheet
Application.ScreenUpdating = False
Sheets("Run").Activate
RCount = Range(Range("F5000").End(xlUp), Range("F4")).Rows.Count
For n = 1 To RCount
test.Name = Sheets("Run").Range("F4").Offset(n - 1, 0)
Next n
Application.ScreenUpdating = False
End sub
推荐答案
您创建新工作表的操作不在重命名的循环之内。您将创建一个新的工作表并重命名多次。
Your operation to create the new worksheet(s) was outside the loop to rename. You would create a new worksheet and rename it a number of times.
Sub new_1()
Dim RCount As Integer
Dim n As Integer
Application.ScreenUpdating = False
With Sheets("Run")
RCount = .Range(.Range("F" & Rows.Count).End(xlUp), .Range("F4")).Rows.Count
For n = 1 To RCount
Sheets("Security Distribution").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = .Range("F4").Offset(n - 1, 0).Value
Next n
End With
Application.ScreenUpdating = False
End Sub
这篇关于根据名称列表命名工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文