Excel VBA启动一个子

时间:2018-09-26 18:14:40

标签: excel vba excel-vba

如何启动以下代码?

Worksheets("Sheet1").Activate 
    'Can't select unless the sheet is active 
Dim Title As Integer, result As String 
titleDetail = Range("A1").Value 
If titleDetail = "Title" Then result = "Hyperlink" 
Selection.Offset(1, 0).Range("A1").Value = result   

任何脚本总是必须以Private Sub,Public Sub等开头是否正确?如何确定使用哪个?

其次,当我声明我的范围(titleDetail = Range(“ A1”)。Value)时,它现在只会在单元格A1中正确显示吗?通过A1:C150中的任何单元格查找的正确语法是什么?

1 个答案:

答案 0 :(得分:1)

类似这样的东西:

Sub RunThis()
    With Worksheets("Sheet1").Range("A1")
        .Offset(1, 0).Value = IIf(.Value = "Title", "Hyperlink", "")
    End With
End Sub