我正在创建一个宏,该宏将向用户询问列的范围,并且对于每一列,将生成一个新的工作表。工作表的名称将与列标题相同。
Dim X As Range
Set X = Application.InputBox(prompt:="Select the column with the code numbers", Title:="New Event Selector", Type:=8)
Dim S As Worksheet
With X
For currentcolumn = 1 To .Columns.Count Step 1
Set S = Sheets.Add(After:=Sheets(Sheets.Count))
S = X.Columns(currentcolumnheader)
Next currentcolumn
End With
我在执行此代码时遇到错误。我无法正确读取列标题。
答案 0 :(得分:0)
这可能是您要寻找的。用户正在使用行标题输入确切的单元格,并且正在填充新的工作表吗?
例如,如果用户输入“ H1:j1”,则它将迭代h1,i1和j1中的任何值作为工作表名称。
Sub YourMacro()
Dim X As Range
Set X = Application.InputBox(prompt:="Select the column with the code numbers", Title:="New Event Selector", Type:=8)
Dim S As Worksheet, ogWSH As Worksheet
Set ogWSH = X.Worksheet
With X
For currentcolumn = 1 To .Columns.Count Step 1
Set S = Sheets.Add(After:=Sheets(Sheets.Count))
S.Name = X.Cells(1, currentcolumn).Value 'make sure this isn't empty
Next currentcolumn
End With
End Sub
我会说a user的混乱空间很大。