Ray小奀 2019-09-10 19:14 采纳率: 0%
浏览 178
已结题

关于Excel Macro中的一个问题,请大神们不吝赐教

各位大神,我在运行这段代码的时候,完全没有效果,好像没有运行一样,小弟是菜鸟一枚,搞了几天都没搞定,请大神们帮帮忙吧!!谢谢了!!!

Sub StepChangeTemplate()

Dim Cur As String
Cur = ""
Dim myRow As Long, myColn As Long
Dim tempName As String, HomeTabName As String
tempName = ""
Dim i As Integer
i = 1
Dim sht As Worksheet

' Read home tab name
HomeTabName = ActiveSheet.Name

' Check if active cell = empty or number
If IsEmpty(ActiveCell) = True Or IsNumeric(ActiveCell) = True Then
MsgBox "Wrong Cell" & vbNewLine & "Please re-select"

Else
' Store cell address into variable and convert to coordinates
Cur = ActiveCell.Address
myRow = Range(Cur).Row
myColn = Range(Cur).Column
' Create multiple sheets with same steps
Do While i = 1
' Store parameters
tempName = Sheets(1).Cells(myRow, myColn).Value
TempCellID = Sheets(1).Cells(myRow, myColn - 1).Value
' Create new sheets
Sheets.Add(After:=Sheets(Sheets.Count)).Name = tempName

    ' hyperlink to coresponding sub-sheet
    Sheets(1).Select
    Cells(myRow, myColn).Select
    Sheets(1).Cells(myRow, myColn).Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'" & tempName & "'!A1", TextToDisplay:=tempName

    ' Write parameters into new cells
    Sheets(tempName).Range("A1").Value = TempCellID
    'Range("B1").Value = tempName ---- no need to write again as hyperlink below syntex TextToDisplay will rewrite the cell

    ' hyperlink to coresponding main sheet
    Sheets(tempName).Select
    Range("B1").Select
    Sheets(tempName).Range("B1").Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:="'" & HomeTabName & "'!A1", TextToDisplay:=tempName

    ' move cursor to next cell
    myRow = myRow + 1
    ' loop index
    If IsEmpty(Sheets(1).Cells(myRow, myColn)) = True Then
        i = 0
    Else
        i = 1
    End If ' End if, it will report compile loop error 'loop without DO' without it
Loop ' End Loop

'AutoFit Every Worksheet Column in a Workbook
For Each sht In ThisWorkbook.Worksheets
    sht.Cells.EntireColumn.AutoFit
Next sht

End If

End Sub

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2019-09-10 22:10
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器