我有一个基于以下图片的问题:
有7个组,每个组有两列,每列之间有一个空白列。
我想为每个组创建一条堆叠线,并将图片放在另一张纸上。例如,我想从A列和B列创建一个堆叠的行并放入工作表X1,然后从D列和E列创建一个堆叠的行,并放入表X2等...是否有任何可能性来命名工作表那个形式,以便把字母“X”和数字?
问题是: 如何创建工作表并用Xi命名它们(如果我有100组2列,我应该有100个名为X1,X2,X3的新工作表,... X100)并将特定工作表中每一组的堆叠线放在一起?
谢谢!
答案 0 :(得分:1)
我已经提供了步骤 -
1)打开excel工作簿2)按Alt + f11,转到插入模块,3) 将代码粘贴到模块中4)转到sheet1 5)插入形状 示例矩形6)右键单击形状,您可以找到assign 宏7)选择宏,这里是Macro_Test 8)现在你可以运行宏了 通过单击形状。形状将作为按钮9)运行后,它 会要求你选择一个文件。
请查看代码。它将满足您的要求
Sub Macro_Test()
Dim LastCol As Long
Dim ws As Worksheet
Dim wb As Workbook
Dim x As Long
Dim wsx As Worksheet
Dim col_num As Long
MsgBox " Please Select the file"
filename = Application.GetOpenFilename
Set wb = Workbooks.Open(filename)
Set ws = wb.Worksheets("Sheet1")
col_num = 1
With ws
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
'~ for calculting no of sheet
x = LastCol / 3
For i = 1 To x
wb.Worksheets.Add().Name = "X" & i
Set wsx = wb.Worksheets("X" & i)
wsx.Columns(1).Value = ws.Columns(col_num).Value
ws.Application.CutCopyMode = False
ws.Application.CutCopyMode = True
wsx.Application.CutCopyMode = False
wsx.Application.CutCopyMode = True
wsx.Columns(2).Value = ws.Columns(col_num + 1).Value
ws.Application.CutCopyMode = False
ws.Application.CutCopyMode = True
wsx.Application.CutCopyMode = False
wsx.Application.CutCopyMode = True
col_num = col_num + 3
Next
End Sub