简体   繁体   中英

Excel VBA starting a Sub

How would I start the below code?

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   

Any script always has to begin with either Private Sub, Public Sub, etc. correct? How do I determine which to use?

Secondly, when I declare my range (titleDetail = Range("A1").Value) right now its only going to look in cell A1 correct? What would be the proper syntax to look through any cells from A1:C150?

Something like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM