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
Excel-返回以上一个hypen中的特定字母结尾的单元格_Excel_Vba - Fatal编程技术网

Excel-返回以上一个hypen中的特定字母结尾的单元格

Excel-返回以上一个hypen中的特定字母结尾的单元格,excel,vba,Excel,Vba,我在col1中有几个值。每个值的格式都有连字符。我只想返回最后一个连字符的第一个字母为“N”的值。 这里有一个简单的代码供您尝试 Sub findN() Dim i As Long, str As String, j As Long j = 2 For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row str = Replace(Cells(i, 1), "-", "", , (Len(Cells(i, 1)) - Len(Replace(Cells

我在col1中有几个值。每个值的格式都有连字符。我只想返回最后一个连字符的第一个字母为“N”的值。
这里有一个简单的代码供您尝试

Sub findN()
Dim i As Long, str As String, j As Long
j = 2
For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
    str = Replace(Cells(i, 1), "-", "", , (Len(Cells(i, 1)) - Len(Replace(Cells(i, 1), "-", "")) - 1))
    str = Mid(str, InStr(str, "-") + 1, Len(str))
    If Left(str, 1) = "N" Then
        Cells(j, 2) = Cells(i, 1)
        j = j + 1
    End If
Next i
End Sub

您已经尝试过什么?它总是从结尾开始的最后三个字符吗?它总是在最后一个催眠之后第一个字符应该是逻辑的,我们可以从反面检查催眠,这将是从反面开始的第一个催眠,并检查催眠之后的字符串。。如果为N,则返回单元格值,查看拆分和左键