我创建了一个包含许多项目的用户表单。在另一个工作表中,我有一个具有特定网址的项目列表。我想要Userform为我插入超链接。我已经提出了下面的代码,当不属于irow时,它可以工作。
我使用以下代码进行了测试并且工作得很好。
Sub Hyperlinkstest()
Dim rng As Range
Dim ws As Worksheet
Dim ws2 As Worksheet
Set ws = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")
Set rng = ws.Range("B2")
rng.Parent.Hyperlinks.Add Anchor:=rng, Address:=Application.WorksheetFunction.VLookup(ws.Range("A2"), ws2.Range("A:B"), 2, False), TextToDisplay:="Info"
End Sub
但是,当我尝试将其集成到我的用户表单中时,我发现收效甚微。有人可以帮忙吗?我得到的问题是编写代码。这是说我的行与ws.cells(iRow,4).Value = ...有一个预期的结束语句。我相信我只是在这里俯瞰一些东西,需要一双新鲜的眼睛。
Private Sub CommandButton1_Click()
Dim iRow As Long
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim rng As Range
Set ws = Worksheets("Database")
Set ws2 = Worksheets("LookupVals")
Set rng = ws.Cells(iRow, 4)
iRow = ws.Cells.Find(what:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
If RmRef.Value = "" Then
RmRef.SetFocus
MsgBox "Please Enter Room Reference"
Exit Sub
End If
ws.Cells(iRow, 2).Value = RmRef.Value
ws.Cells(iRow, 3).Value = RetMod.Value
ws.Cells(iRow, 4).Value = rng.Parent.Hyperlinks.Add Anchor:=rng, Address:=WorksheetFunction.VLookup(RetMod.value, ws2.Range("A:B"), 2, False), TextToDisplay:="Info"
ws.Cells(iRow, 5).Value = OdCd.Value
ws.Cells(iRow, 6).Value = hmm.Value
ws.Cells(iRow, 7).Value = lmm.Value
ws.Cells(iRow, 8).Value = rdtyp.Value
ws.Cells(iRow, 9).Value = dtt.Value
ws.Cells(iRow, 10).Value = Wts.Value
ws.Cells(iRow, 11).Value = Qt.Value
ws.Cells(iRow, 12).Value = LP.Value
ws.Cells(iRow, 13).Value = Dc.Value
ws.Cells(iRow, 14).Value = TP.Value
'clear the data
RmRf.Value = ""
Rdd.Value = ""
OdCd.Value = ""
hmm.Value = ""
lmm.Value = ""
rdtyp.Value = ""
dtt.Value = ""
Wts.Value = ""
Qt.Value = ""
LP.Value = ""
Dt.Value = ""
TTpr.Value = ""
End Sub