简体   繁体   English

Excel VBA“查找”命令

[英]Excel VBA “Find” Command

I need to retrieve a value from a cell, then find that value in a named range (GasDip) and return the value from the cell to the right of the found cell to the current worksheet. 我需要从一个单元格中检索一个值,然后在命名范围(GasDip)中找到该值,并将该值从找到的单元格右侧的单元格返回到当前工作表。 This is what I have: 这就是我所拥有的:

Dim GasDipVal As String
Dim DipAMount As Integer

GasDipVal = Range("gasdipamt").Value

Application.Goto Reference:="GASDIP"
Selection.Find(What:="GasDipval", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlWhole, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase _
    :=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, 1).Range("A1").Select
DipAMount = ActiveCell.Value
Application.Goto Reference:="DATE"
ActiveCell.Offset(1, 11).Range("A1").Select
ActiveCell.Value = DipAMount

The error occurs when it reached the "Selection.Find" command. 到达“ Selection.Find”命令时,发生错误。 It won't recognize the "GasDipValue" If I search for a static number that I put inside of qutes, it works. 它不会识别“ GasDipValue”。如果我搜索放置在qutes中的静态数字,它将起作用。

Please help!! 请帮忙!! Thanks in advance. 提前致谢。

It sounds like you could probably use the function VLOOKUP to do the job for you. 听起来您可能可以使用VLOOKUP函数为您完成这项工作。

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

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