热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将公式给出的单元格值声明为字符串-DeclareCellvaluegivenbyformulaasstring

HithereIhaveaformulathatdisplaysavalueinacell,howeverIcannotdeclarethevalueoftha

Hi there I have a formula that displays a value in a cell, however I cannot declare the value of that cell as string in a VBA code as it's not a "real" value but a dynamic one based on the formula. How would I go about using the value as a string? Is there any way to convert a result given by a formula to string via VBA?

嗨,我有一个公式,在单元格中显示一个值,但是我无法在VBA代码中将该单元格的值声明为字符串,因为它不是“真实”值,而是基于公式的动态值。我如何将该值用作字符串?有没有办法通过VBA将公式给出的结果转换为字符串?

This is the formula in cell I1: =IFERROR(VLOOKUP(J3,REVIEWERS!A:C, 3, 0),"")

这是单元格I1中的公式:= IFERROR(VLOOKUP(J3,REVIEWERS!A:C,3,0),“”)

I am trying to declare the value in I1 as string with the following code:

我试图使用以下代码将I1中的值声明为字符串:

Public list As Worksheet
Public bsawt as worksheet
Sub BSAW_Export()
Dim ReviewerID As String

    Set list = Sheets("LIST")
    Set bsawt = Sheets("BSAW_TABLE")
    ReviewerID = list.Range("I1").Value

    lastrow = list.Cells(Rows.Count, "E").End(xlUp).Row
    For x = 2 To lastrow

        If bsawt.Range("E" & x).Value <> " error" Then bsawt.Range("F" & x).Value = ReviewerID

    Next x

End Sub

3 个解决方案

#1


1  

Simplest is to use the .Text property instead

最简单的方法是使用.Text属性

ReviewerID = list.Range("I1").Text

#2


1  

Try CStrfunction? CStr function

试试CStrfunction? CStr功能

Public list As Worksheet
Public bsawt As Worksheet
Sub BSAW_Export()

Dim ReviewerID As String

    Set list = Sheets("LIST")
    Set bsawt = Sheets("BSAW_TABLE")
    ReviewerID = CStr(list.Range("I1").Value)

    lastrow = list.Cells(Rows.Count, "E").End(xlUp).Row
    For x = 2 To lastrow

        If bsawt.Range("E" & x).Value <> " error" Then bsawt.Range("F" & x).Value = ReviewerID

    Next x

End Sub

#3


1  

Without VBA

The usual way to convert a formula's output to text is:

将公式输出转换为文本的常用方法是:

=TEXT(IFERROR(VLOOKUP(J3,REVIEWERS!A:C, 3, 0),""),"General")

If you have a specific text-format in mind like Date or Currency, then just replace the "General"

如果您有特定的文本格式,如日期或货币,那么只需替换“常规”


推荐阅读
author-avatar
苏格兰的秋天
一枚在创业路上坚持走下去的人。。。。
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有