简体   繁体   English

VBA Vlookup公式,值未出现在单元格中

[英]VBA Vlookup formula, value does not appear in cell

My problem is that when i put this code in VBA: 我的问题是,当我将此代码放入VBA时:

Sub formula_vlookup()
                                'MONTHS
ActiveSheet.Cells(ActiveCell.Row, 1).Select
ActiveCell.Offset(0, 16).Select
With ActiveCell
    .formula = "=IF(ISNA(VLOOKUP(" & .Offset(0, -16).Address(0, 1) & ",'CZ support'!$A:$AA,2,0)), _ 
"""",(VLOOKUP(" & .Offset(0, -16).Address(0, 1) & ",'CZ support'!$A:$AA,2,0)))"

End With
End Sub    

It works perfectly ( i mean , it gives me the value of the cell that is "vlooked up" but the problem is that it does not display that value in the cell, so the only way to know if its a value there is making a SUM of the cells that contain this formula. 它可以完美地工作(我的意思是,它给了我“ vlooked”单元格的值,但问题是它没有在单元格中显示该值,因此唯一的方法就是知道它的值是否在包含此公式的单元格的总和。

how can i manage this problem? 我该如何解决这个问题? Thank you in advance for your help 预先感谢您的帮助

Things to check: 检查事项:

  • Name [CZ Support] (with a BLANK in the middle) may be invalid ... I can't create that in XLS2010 名称[CZ支持](中间有空白)可能无效...我无法在XLS2010中创建该名称
  • check that the name exists (Name manager or just try to select it from the drop down left of formula bar) 检查名称是否存在(名称管理器,或尝试从编辑栏的左下方选择名称)
  • Try entering the same formula (with .Offset(...) expanded to actual cell addresses) directly in worksheet cell(s) 尝试直接在工作表单元格中输入相同的公式( .Offset(...)扩展为实际单元格地址)
  • Try replacing the "" in the FALSE part of the =IF(...) by some text (eg "not found") to see if you're caught by an exception 尝试用一些文本(例如“ not found”)替换=IF(...)的FALSE部分中的“”,以查看是否被异常捕获
  • Try replacing the last VLOOKUP argument (0) by TRUE or FALSE as per the documentation 尝试按照文档将TRUE或FALSE替换最后一个VLOOKUP参数(0)
  • Try assigning the formula to a string variable first and examine it in the debugger window (or do a Debug.Print thereof) 首先尝试将公式分配给字符串变量,然后在调试器窗口中对其进行检查(或对其进行Debug.Print)
  • pasting your code "as is" gave me an error - my VBA doesn't like the line splitting underscore in the formula generation 按原样粘贴您的代码给我一个错误-我的VBA不喜欢公式生成中的行拆分下划线

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

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