简体   繁体   English

VBA使用Vlookup将值放入单元格

[英]VBA Use Vlookup to place a Value into cell

I'm pretty new to VBA and this has me stumped. 我对VBA还是很陌生,这让我很困惑。 I hope there is an easy way to do this. 我希望有一个简单的方法可以做到这一点。 I know the following doesn't work, but it's an easy way to show what I'd like to do: 我知道以下方法不起作用,但这是显示我想做的一种简单方法:

Application.WorksheetFunction.VLookup(date, .Range("A:A"), 2, False) = String

Basically I want to look up a date in a column A, go to the second Column and insert the string. 基本上,我想在A列中查找日期,转到第二个Column并插入字符串。

I've searched and can't find what I'm looking for. 我已经搜索过,找不到想要的东西。

Thanks in advance, 提前致谢,

Cory 科里

We can use MATCH() to find the row and deposit the string with the correct offset from column A : 我们可以使用MATCH()查找行,并以距列A正确的偏移量存放字符串:

Sub Spiral()
    Dim s As String, i As Long

    s = "whatever"
    i = Application.WorksheetFunction.Match(CLng(Date), Range("A:A"))
    Cells(i, 2).Value = s
End Sub

You can use Range.Find 您可以使用Range.Find

Dim cell As Range
Set cell = .Range("A:A").Find(date, , , xlWhole)
If Not cell Is Nothing Then cell(, 2) = String ' or cell.Offset(, 1) = String

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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