[英]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.