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 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?