1

過去数日間、次のことができるマクロを書くのに苦労しています:1.特定のセルを1つのシートからコピーします(コピーするかどうかは条件によって異なります)2.指定したシートに貼り付けます(その名前式で指定されている)を指定されたセルに挿入します(それらも式で指定されています)。

残念ながら画像を貼り付けることはできないので、コードのスケッチと質問を貼り付けて、何をしようとしているのかを説明しようと思います。この漠然とした場合は、私に知らせてください。

Sub The_One()
'
For Each c In Worksheets("fsr").Range("O:O")
    If c.Value = "p" Then
    'Now I do not know how to make Excel copy the cells from current row from columns E,F,G,H
    'Now I would like to add cells into the worksheet which name is sepcified by the formula from column P.
    'Inserted cells should be added into a row given by the formula in column Q.
    'I imagine it like that:
        Sheets("group1").Select 'This "group1" cannot be simply tiped into the code, it should be taken from Column P in worksheet("fsr")
        Range("A3:I3").Select 'As above, the range should be specified more like that:
                              'Range("A[row number given by a formula in column Q in Worksheet("fsr")]:I[the same number as before]
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
            'Now I would like to copy four cells from Worksheet("fsr") they are in the same row as the current cell from above For Each
            'I imagine it somehow like that:
            Range("E'Here I dont know how to define the row number':H'The same problem'").Activate
            ActiveCell.CurrentRegion.Select 'Is CurrentRegion suitable?
            Selection.Copy
            Worksheets("group1").Select 'But this worksheet should be the one that is given by a formula in column P in Worksheet("fsr")
            Range("E'Here I dont know how to define the row number':F'The same problem'").Activate
            ActiveSheet.Paste 'But I dont want to paste it anywhere. It sholud be pasted into the worksheet given by the formula from column P,
                              'into the row given by the formula from column Q, into the columns C,D,E,F. So:
                              'So when the For Each starts to go trough Range("O:O") in Worksheet("fsr") it notices that there is "p" so it should:
                              'copy cells E2:H2 (because this "p" is in the second row) and paste it in the Worksheet("group1") (because this is what
                              'we find in cell P2 into the cells C3:F3 (row 3 because "3" is what we find in Q2)
    End If
Next c
End Sub

私は Stackoverflow を初めて使用するので、ここでの私の行動に関するすべてのコメントに感謝します。あなたが私を助けてくれることを願っています。本当にあなたの助けが必要です。敬具 Artur Rutkowski

4

1 に答える 1