Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用vba删除引号?_Vba_Excel - Fatal编程技术网

如何使用vba删除引号?

如何使用vba删除引号?,vba,excel,Vba,Excel,我有: 但我不想要双引号。我想要nuid=!,@,a-z 建议我删除起始引号和结束引号的方法 这是我的密码: nuid="!,@,a-z" 在我的gui中,我将输入特殊字符,这些字符将存储在变量nuid中。我只需要特殊字符,而不需要它周围的引号基本上用转义“” 下面应该有帮助 sub highlight(nuid as string) dim sh3 as worksheet Set sh3 = Thisworkbook.Worksheets("Sheet1") sh3.Select

我有:

但我不想要双引号。我想要nuid=!,@,a-z

建议我删除起始引号和结束引号的方法

这是我的密码:

nuid="!,@,a-z"
在我的gui中,我将输入特殊字符,这些字符将存储在变量nuid中。我只需要特殊字符,而不需要它周围的引号

基本上用
转义

下面应该有帮助

sub highlight(nuid as string)

dim sh3 as worksheet

Set sh3 = Thisworkbook.Worksheets("Sheet1")

sh3.Select

Cells.Find("User ID").Select

ActiveCell.Offset(1, 0).Select

nuid = Replace(nuid, """", "")

Set rn = sh3.UsedRange
  k = rn.Rows.Count + rn.Row - 1
  For x = 1 To k

 If ActiveCell.Value Like nuid Then

 Selection.Interior.Color = vbYellow

 Else

 Selection.Interior.ColorIndex = xlNone

End If

ActiveCell.Offset(1, 0).Select 'moves activecell down one row.

Next

end sub
您也可以尝试:

nuid=Replace(nuid,Chr(34),vbNullString)

但是,如果不是第一个或最后一个字符加引号,则可能会出现问题,例如:
“!,@,“a-z”

在这种情况下,您可以尝试:

numid=Mid(numid,2,Len(numid)-1)
这将剪切第一个和最后一个字符

编辑: 在我看来,您看到的引号表示变量字符串的类型

Edit2-观察窗口

结果:

Edit3-带有sub 4 Sagi:

nuid = replace (nuid, """", "")
附加变体

Sub Highlight4Sagi(SpecChar As String)

Dim Column As Integer
SpecChar = "!@#"

ThisWorkbook.Worksheets(1).Select
Column = Cells.Find("User ID").Column

LastRow = Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row

For i = 2 To LastRow 'loop each row in column "User ID"
    For j = 1 To Len(SpecChar) 'loop every specchar: ! and @ and # and find him in each cells
        If InStr(1, Cells(i, Column), Mid(SpecChar, j, 1)) > 0 Then
        Cells(i, Column).Interior.ColorIndex = 6
        Exit For
        Else
        Cells(i, Column).Interior.ColorIndex = 0
        End If
    Next j
Next i

End Sub
子高亮显示(nuid为字符串)
尺寸sh3作为工作表,Cl&,Lrow&,x&,oCell作为范围
Set sh3=此工作簿。工作表(“表1”)
Cl=sh3.Cells.Find(“用户ID”)列
Frow=sh3.Cells.Find(“用户ID”).Row+1
Lrow=单元格。查找(“*”,xlByRows,xlPrevious)。行
对于sh3.范围内的每个oCell(单元格(Frow,Cl),单元格(Lrow,Cl))
如果oCell.Value为“”,则
对于x=1到Len(nuid)
如果oCell.Value像“*”和Mid(numid,x,1)和“*”那么
oCell.Interior.Color=vbYellow
退出
其他的
oCell.Interior.Color=xlNone
如果结束
下一个x
如果结束
下奥塞尔
端接头
输出


但是,如果您需要查找,例如,包含小写字符的单元格,则应使用另一个aproach搜索。不起作用:/nuid的值仍然是“!,@,a-z”我尝试将“nuid=Replace(nuid,”,“,”)替换为“nuid=Mid(nuid,2,Len(nuid)-1”,但仍然是nuid=“!,@,a-z”的值@sagi:您可以这样运行此sub:
突出显示(!,@,a-z))
?在我看来,您看到的引号表示变量
字符串的类型,请参阅我的answer@sagi:您可以添加有问题的数据,但此过程无法按预期工作?从我的gui中输入特殊字符,如-!,@,这将传递到我的vb脚本。当传递时,它将被保存ed为“!,@”,我不想这样。我应该更改变量类型吗?@Dawid
Sub highlight(nuid As String)
    Dim sh3 As Worksheet, Cl&, Lrow&, x&, oCell As Range
    Set sh3 = ThisWorkbook.Worksheets("Sheet1")
    Cl = sh3.Cells.Find("User ID").Column
    Frow = sh3.Cells.Find("User ID").Row + 1
    Lrow = Cells.Find("*", , , , xlByRows, xlPrevious).Row
    For Each oCell In sh3.Range(Cells(Frow, Cl), Cells(Lrow, Cl))
        If oCell.Value <> "" Then
            For x = 1 To Len(nuid)
                If oCell.Value Like "*" & Mid(nuid, x, 1) & "*" Then
                    oCell.Interior.Color = vbYellow
                    Exit For
                Else
                    oCell.Interior.Color = xlNone
                End If
            Next x
        End If
    Next oCell
End Sub