Excel 切换工作表以及从工作表A复制和粘贴到工作表B的问题

Excel 切换工作表以及从工作表A复制和粘贴到工作表B的问题,excel,copy-paste,vba,Excel,Copy Paste,Vba,我正在尝试检查表A中A列的值,如果是,则B列和C列中的值需要复制到表B中的A列和B列。这需要循环,直到它检查了所有值并检查了所有行。 代码会执行,但它只会将值复制到同一工作表上,并且只会对第一行值执行此操作。我尝试过选择和激活,但没有效果。代码如下: Dim Count As Integer 'Count from workbook open Dim CountVal As Integer Dim Check As String 'check value for ye

我正在尝试检查表A中A列的值,如果是,则B列和C列中的值需要复制到表B中的A列和B列。这需要循环,直到它检查了所有值并检查了所有行。 代码会执行,但它只会将值复制到同一工作表上,并且只会对第一行值执行此操作。我尝试过选择和激活,但没有效果。代码如下:

Dim Count As Integer        'Count from workbook open
Dim CountVal As Integer
Dim Check As String        'check value for yes or no
Dim ufCheckvalue As Integer      'Gets go/nogo from userform
Dim Row1 As Integer         'row number for add/remove sheet
Dim Row2 As Integer         'row number for summary sheet
Dim SecNum As Integer       'value for section number
Dim Descrip As String   'value for description

ListCount = Range("B" & Rows.Count).End(xlUp).Row
Count = ListCount         'initalize values
CountVal = 0
Check = ""
ufCheckvalue = 0
Row1 = 10       'first row of values on add/remove sheet
Row2 = 5        'first row of values on summary sheet
SecNum = 0
Descrip = ""

ufContinue.Show       'user has to confirm it wants to run program
If ufCheckvalue = 1 Then
Unload ufContinue
    Do
    Check = Range(Cells(1, Row1)).Value                 'gets the check value
        If Check = "Yes" Then                           'checks to see if yes
            SecNum = Range(Cells(2, Row1)).Value        'sets values if yes
            Descrip = Range(Cells(3, Row1)).Value
            Sheets("Summary of Estimate").Select        'selects estimate page
            Selection.Activate                          'activates estimate page
            Range(Cells(1, Row2)).Select                'selects cell to insert value into
                Selection.Value = SecNum                'inserts value
            Range(Cells(2, Row2)).Select                'selects cell to insert value into
                Selection.Value = Descrip               'inserts value
            Sheets("Add-Remove").Select                 'goes back to original worksheet
            Row2 = Row2 + 1                             'adds one to row2 so it will index to next line
        End If
        Row1 = Row1 + 1                                 'changes rows for check value
        CountVal = CountVal + 1                         'adds one to count value
    Loop Until CountVal = Count                         'loops until it has looped countval number of times

ElseIf ufCheck = 0 Then                                 'makes the update button visible
Unload ufContinue
cmdUpdate.Visible = True    'Shows the update button
End If

如果这真的没有道理,我向你道歉。我在大学里学到了很多危险的东西

读这篇文章:终于回到了这篇文章的代码中。我试过你的回答,但似乎没有得到任何价值。我的猜测是,在“A”列中有空白单元格,我如何修改它以在空白空间上运行?
Set ws = Worksheets("Summary of Estimate")
Set ws2 = Worksheets("Add-Remove")
Dim i As Integer

For i = 1 To ws.Range("A" & Rows.Count).End(xlUp).Row
    If ws.Range("a" & i).Value = "Yes" Then
    ws.Range("b" & i).Value = ws2.Range("a" & i).Value
    ws.Range("c" & i).Value = ws2.Range("b" & i).Value
    End If
Next i