代码之家  ›  专栏  ›  技术社区  ›  three3

如何插入双引号或单引号

  •  26
  • three3  · 技术社区  · 15 年前

    “艾伦”或“艾伦”

    附言:

    我在网上发现其他人需要做和我一样的事情,这个解决方案对他们有效,但我不知道该怎么办:

    变量(例如myCell)然后 用它来迭代“选择” 像这样的范围对象集合

    Sub AddQuote()
    Dim myCell As Range
        For Each myCell In Selection
            If myCell.Value <> "" Then
                myCell.Value = Chr(34) & myCell.Value
            End If
        Next myCell
    End Sub
    

    另一个同样适用于其他人的解决方案是:

    Sub OneUglyExport()
    
    Dim FileToSave, c As Range, OneBigOleString As String
    
    FileToSave = Application.GetSaveAsFilename
    
    Open FileToSave For Output As #1
    
    For Each c In Selection
    
    If Len(c.Text) <> 0 Then _
    
        OneBigOleString = OneBigOleString & ", " & Chr(34) & Trim(c.Text) & Chr(34)
    
    Next
    
    Print #1, Mid(OneBigOleString, 3, Len(OneBigOleString))
    
    Close #1
    
    End Sub
    
    6 回复  |  直到 5 年前
        1
  •  44
  •   Community Mohan Dere    5 年前

    从未引用的值创建新的引用值

    • A列包含名称。
    • 将下列公式放入B列 = """" & A1 & """"

    Public Function Enquote(cell As Range, Optional quoteCharacter As String = """") As Variant
        Enquote = quoteCharacter & cell.value & quoteCharacter
    End Function
    

    =OfficePersonal.xls!Enquote(A1)

    =OfficePersonal.xls!Enquote(A1, "'")

        2
  •  22
  •   dendarii    15 年前

    假设您的数据在A列中,请在B列中添加一个公式

    ="'" & A1 & "'" 
    

        3
  •  19
  •   noobsee    9 年前

    更简单的步骤:

    1. 将以下内容复制/粘贴到类型字段中:
    2. 完成!
        4
  •  7
  •   Kevin Mansel    13 年前

    为什么不为需要引用的单元格使用自定义格式呢?

    如果为单元格列设置自定义格式,则所有值都将采用该格式。

    对于数字…比如邮政编码…应该是这个“#” 对于字符串文本,应该是“@”

    将文件保存为csv格式,并根据需要将所有引号括在单元格数据周围。

        5
  •  7
  •   spriteup    10 年前

    或选择范围和格式单元格>自定义\“@”

        6
  •  0
  •   Slartibartfast    15 年前

    推荐文章