Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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 excel:如何将字符从一个单元格复制到另一个单元格_Excel_Vba - Fatal编程技术网

vba excel:如何将字符从一个单元格复制到另一个单元格

vba excel:如何将字符从一个单元格复制到另一个单元格,excel,vba,Excel,Vba,我是VBA世界的新手,我正在学习你的建议 我已经寻找了几种解决方案,并尝试了它们,但它们对我的问题并不理想 这里是链接 我需要的是检查输入中的字符并与匹配列表键匹配的可能性。匹配字符串后,复制输出中的字符I 如您所见,第一行很容易匹配,但在一个8单元中,例如有一个包含14个字符的字符串。 在本例中,我需要它,当有一个以CMXXAB开头的字符串时,匹配的是WT ALWAYS!。 当我们有A12时也会发生同样的事情:它以ETRxxx开始,比赛结束后将以JAZZ之类的输出开始。我认为这将帮助您: Op

我是VBA世界的新手,我正在学习你的建议

我已经寻找了几种解决方案,并尝试了它们,但它们对我的问题并不理想

这里是链接

我需要的是检查输入中的字符并与匹配列表键匹配的可能性。匹配字符串后,复制输出中的字符I

如您所见,第一行很容易匹配,但在一个8单元中,例如有一个包含14个字符的字符串。 在本例中,我需要它,当有一个以CMXXAB开头的字符串时,匹配的是WT ALWAYS!。
当我们有A12时也会发生同样的事情:它以ETRxxx开始,比赛结束后将以JAZZ之类的输出开始。

我认为这将帮助您:

Option Explicit

Sub test()

    Dim LastrowA As Long, i As Long, AppearA As Long, AppearB As Long
    Dim strA As String, strB As String


    With ThisWorkbook.Worksheets("Sheet1")

        LastrowA = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 1 To LastrowA

            strA = .Range("A" & i).Value
            strB = .Range("C" & i).Value

            'Check if strA appears in strB
            AppearA = InStr(1, strB, strA)
            If AppearA > 0 Then
                .Range("B" & i).Value = strA
                Exit For
            End If

            'Check if strB appears in strA
            AppearB = InStr(1, strA, strB)
            If AppearB > 0 Then
                .Range("B" & i).Value = strB
                Exit For
            End If

        Next i

    End With

End Sub
非常感谢你的帮助。 几天后,我找到了问题的解决办法。 事实上,这是我的解决方案,我希望能很好地帮助任何需要这样东西的人


End Sub

如果您向我们展示您的代码,您将获得更好的帮助!嗯,我还没有。我正在尝试生成一个,但我现在的经验是有限的,除了爵士乐和WT的规则之外,还有其他特殊规则吗?此外,您的数据屏幕截图对于进行正确的故障排除几乎毫无用处。无法将其复制/粘贴到工作表中。对于那些可能帮助你的人来说,不得不手动输入是令人沮丧的。为了使数据有用,请编辑您的问题,将其作为文本发布,或者使用此功能,或者可能将删除敏感信息的工作簿上载到某个公共网站,并在原始问题中发布链接。非常感谢。真的。特殊规则只适用于爵士乐和wt
Sub AssociazioneRotabiliPerPivot()

Dim LastrowA, LastrowC As Long, i, j As Long, AppearA As Long, AppearB As Long
Dim strA As String, strB As String

With ThisWorkbook.Worksheets("sheet1")

    LastrowA = .Cells(.Rows.count, "A").End(xlUp).Row
    LastrowC = .Cells(.Rows.count, "C").End(xlUp).Row

    For j = 1 To LastrowC   

        For i = 1 To LastrowA   

            strA = .Range("A" & i).Value
            strB = .Range("C" & j).Value

            AppearC = InStr(1, strA, strB)
            If AppearB > 0 Then
                .Range("B" & i).Value = strB
            End If

            If (InStr(1, strA, "CM") Or InStr(1, strA, "C4551R")) > 0 Then

                .Range("B" & i).Value = "WT"   

            ElseIf InStr(1, strA, "ETR425") > 0 Then   

                .Range("B" & i).Value = "JAZZ"  

            End If

        Next i

    Next j

End With