0

H列にこのリストがあります。

ここに画像の説明を入力

ここに私のマクロExcelコードがあります

Sub TheSpaceBetween1()
    Dim ws As Worksheet
    Dim LRow As Long, i As Long
    Dim insertRange As Range

    '~~> Chnage this to the relevant sheet
    Set ws = ActiveSheet

    '~~> Work with the relevant sheet
    With ws
        '~~> Get the last row of the desired column
        LRow = .Range("H" & .Rows.Count).End(xlUp).Row

        '~~> Loop from last row up
        For i = LRow To 1 Step -1
            '~~> Check for the condition
            '~~> UCASE changes to Upper case
            '~~> TRIM removes unwanted space from before and after
            If UCase(Trim(.Range("H" & i).Value)) = "NOT THE SAME" Then
                '~~> Insert the rows
                Selection.FormulaArray = "=MIN(IF(C[-7]=RC[-7],C[-6]))" <----this is the problem
            End If
        Next i
    End With
End Sub

残念ながら、それは機能していません。NOT THE SAMEという単語をこの式に置き換えることを想定しています

Selection.FormulaArray = "=MIN(IF(C[-7]=RC[-7],C[-6]))"

マクロがすることは

すべてのセルの内容を数式の NOT THE SAME というテキストに置き換えますSelection.FormulaArray = "=MIN(IF(C[-7]=RC[-7],C[-6]))"

コードを機能させるのに役立つ人はいますか?

4

1 に答える 1

1

すでにサントッシュは正しい答えを提供しましたが、彼は答えを追加するのを逃したと思い(.FormulaArray)ます..以下は私にとってはうまくいきました(テスト済み)

Sub TheSpaceBetween1()
    Dim ws As Worksheet
    Dim LRow As Long, i As Long
    Dim insertRange As Range

    '~~> Chnage this to the relevant sheet
    Set ws = ActiveSheet

    '~~> Work with the relevant sheet
    With ws
        '~~> Get the last row of the desired column
        LRow = .Range("H" & .Rows.Count).End(xlUp).Row

        '~~> Loop from last row up
        For i = LRow To 1 Step -1
            '~~> Check for the condition
            '~~> UCASE changes to Upper case
            '~~> TRIM removes unwanted space from before and after
            If UCase(Trim(.Range("H" & i).Value)) = "NOT THE SAME" Then
                '~~> Insert the rows
                .Range("H" & i).FormulaArray = "=MIN(IF(C[-7]=RC[-7],C[-6]))"  ' <----this is the problem
            End If
        Next i
    End With
End Sub
于 2013-09-26T12:15:20.540 に答える