对不起,我的语言,不是母语。
所以这就是可能的问题。
有一个包含大约30张工作表和数据的工作簿。我需要根据工作表的名称将数据转换为某种格式。我为每种格式创建了一个marco,它可以很好地工作,并适用于所有选定的工作表。我的想法是创建一个宏来调用三个format-marcos中的一个,然后检查工作表的名称并格式化数据。像这样的东西
If sheet.name = "111, 112, 113..." then 'if it fit the name do the format-1
call "Module_name_1"
Else if sheet.name = "222, 223, 224..." then 'if it fit the name do the format-2
call "Module_name_2"
Else sheet.name = "333, 334, 335..." then 'if it fit the name do the format-3
call "Module_name_3"无论如何,感谢您抽出时间=)
发布于 2016-12-16 22:48:59
可以使用select case语句检查名称。这里的数字应该在比较时转换为字符串。这样,您可以根据您的值轻松地进行分支。如果需要更改限制,请更改119、229和339。
Select Case sheet.name
Case 111 To 119
'if it falls into the region then do the format-1
call "Module_name_1"
Case 222 To 229
'if it fit the name do the format-2
call "Module_name_2"
Case 333 To 339
'if it fit the name do the format-3
call "Module_name_3"
End Select发布于 2016-12-16 22:45:14
检查所有图纸名称的前两个字符:
Sub SID()
Dim shn As String, sh As Worksheet
Dim shn2 As String
For Each sh In Sheets
shn = sh.Name
shn2 = Left(shn, 2)
If shn2 = "11" Then Call Module_name_1
If shn2 = "22" Then Call Module_name_2
If shn2 = "33" Then Call Module_name_3
Next sh
End Sub发布于 2016-12-29 07:59:04
你甚至不需要“Call”,但它看起来很好,而且可能更直观。如果你真的想简化事情,试着这样做。
Select Case sheet.name Case 111至119 Module_name_1 Case 222至229 Module_name_2 Case 333至339 Module_name_3结束选择
https://stackoverflow.com/questions/41186557
复制相似问题