![](/img/trans.png)
[英]Excel VBA: How to push data to an exclusive range on another sheet?
[英]how to use hlookup in Excel VBA with a range of data from another sheet?
我想使用HLookUp Function
,但是范圍是從另一張紙HLookUp Function
,我無法正確處理。
Sub P()
Dim mes As String
Dim i As Integer
Dim valor As Double
Dim bobes As Range
bobes = Worksheets("Cash Cost EP").Range("C3:S10")
i = 4
Do Until Cells(2, i) = ""
mes = Cells(2, i)
mes = Right(Cells(2, i), 2)
If mes = "01" Then
mes = "Enero"
ElseIf mes = "02" Then
mes = "Febrero"
ElseIf mes = "03" Then
mes = "Marzo"
ElseIf mes = "04" Then
mes = "Abril"
ElseIf mes = "05" Then
mes = "Mayo"
ElseIf mes = "06" Then
mes = "Junio"
ElseIf mes = "07" Then
mes = "Julio"
ElseIf mes = "08" Then
mes = "Agosto"
ElseIf mes = "09" Then
mes = "Setiembre"
ElseIf mes = "10" Then
mes = "Octubre"
ElseIf mes = "11" Then
mes = "Noviembre"
ElseIf mes = "12" Then
mes = Diciembre
End If
Sheets("resumen").Range("d17").Value = "= HLookup(mes, bobes, 3, 0)"
i = i + 1
Loop
End Sub
當我運行代碼時,它無法按我想要的方式工作。
請幫忙,我想在單元格D17
獲取Hlookup
的值。
尚不清楚,因為“不按我想要的方式工作”對於問題所在有些含糊。 我想您需要將以下行更改為:
Sheets("resumen").Range("d17").Value = "=HLOOKUP(" & Chr(34) & mes & Chr(34) _ & ",'" & bobes.Parent.Name & "'!" & bobes.Address & ",3,0)"
這樣您就可以將mes
的值(包括雙引號)而不是文本“ mes”傳遞給函數,並標識工作表和bobes
范圍的范圍地址。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.