0

当我尝试将 Sheet1 中的数据插入 Sheet2 时,我的 VBA 脚本出错。脚本代码仅提供“案例 2-3”行号,第一个“案例”不输入到工作表 2。想知道 VBA 脚本中还应该包含什么来完成流程?

我的 VBA 脚本:

Sub CopyFromSheet1()
    Dim i As Long
    For i = 1 To Sheet1.Cells(Sheet1.Rows.Count, 6).End(xlUp).Row ' Last Cell of Column F

  Select Case CStr(Sheet1.Cells(i, 3).Value) ' Looks at the Value in Column C

    Case "Due From"
        Sheet2.Cells(22, 3).Value = Sheet1.Cells(i, 6).Value
    Case "TOTAL1"
        Sheet2.Cells(23, 3).Value = Sheet1.Cells(i, 6).Value
    Case "TOTAL2"
        Sheet2.Cells(24, 3).Value = Sheet1.Cells(i, 6).Value

    End Select


Next i


End Sub
4

1 回答 1

0

怎么样:你所做的一切都是为了 C 列。然后对 D 列再做一遍吗?

Sub CopyFromSheet1()
    Dim i As Long
    Dim col as Long

    for col = 3 to 4
        For i = 1 To Sheet1.Cells(Sheet1.Rows.Count, 6).End(xlUp).Row ' Last Cell of Column F

            Select Case CStr(Sheet1.Cells(i, col).Value) 

                Case "Due From"
                    Sheet2.Cells(22, 3).Value = Sheet1.Cells(i, 6).Value
                Case "TOTAL1"
                    Sheet2.Cells(23, 3).Value = Sheet1.Cells(i, 6).Value
                Case "TOTAL2"
                    Sheet2.Cells(24, 3).Value = Sheet1.Cells(i, 6).Value

            End Select


        Next i

    next col
End Sub
于 2019-04-12T18:45:58.620 回答