要将值从工作表1复制到工作表2,然后使用vba将其粘贴到所需位置

时间:2013-01-26 16:50:15

标签: excel-vba vba excel

我的目标是从表单“B5”中的单元格复制值并将其粘贴到表格2“C11”以下,代码不能正常工作

Sub SCMPROCUREMENT()

' SUPPLY CHAIN MANAGEMENT PROCUREMENT


Worksheets("Sheet1").Select


Range("B5:B100000").Select

finalrow = Cells(Rows.Count, 2).End(xlUp).Row

For x = 5 To finalrow

If Worksheets("sheet1").Cells(x, 2).Font.Bold = False Then

Worksheets("sheet1").Select

Cells(x, 2).Select

Selection.Copy

ThisWorkbook.Worksheets("Sheet2").Range("C11").Select


ActiveSheet.Paste


End If
Next x

End Sub

2 个答案:

答案 0 :(得分:1)

a)你的 ThisWorkbook.Worksheets(“Sheet2”)。范围(“C11”)不能像那样工作

b)你需要第二个清单的计数器,否则你会继续覆盖C11

Sub SCMPROCUREMENT()

    ' SUPPLY CHAIN MANAGEMENT PROCUREMENT

    Dim count As Integer

    For x = 5 To Worksheets("Sheet1").Cells(Rows.count, 2).End(xlUp).Row

        If Worksheets("Sheet1").Cells(x, 2).Font.Bold = False Then

            Worksheets("Sheet1").Cells(x, 2).Copy

            Worksheets("Sheet2").Cells(11 + count, 3).Select
            ActiveSheet.Paste

            count = count + 1

        End If
    Next x

End Sub

答案 1 :(得分:0)

Sub SCMPROCUREMENT()

    ' SUPPLY CHAIN MANAGEMENT PROCUREMENT

    Application.ScreenUpdating = False

    Dim count As Integer

    With Worksheets("Sheet1")

        For x = 5 To .Cells(Rows.count, 2).End(xlUp).Row

            If .Cells(x, 2).Font.Bold = False Then

                .Cells(x, 2).Copy Worksheets("Sheet2").Cells(11 + count, 3)
                count = count + 1
            End If
        Next x

    End With

    Application.ScreenUpdating = True

End Sub