You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VBA开发需求:将符合条件的行复制至Core_Cutter_List汇总表

VBA Script to Automate Material Request Summary

Got it, let's build that VBA script to automate your material request summary. Here's a reliable solution that does exactly what you need—copy rows from sheet "2" to "Core_Cutter_List" when column A has text and column G is blank:

The Code

Sub CopyToCoreCutterList()
    Dim sourceWS As Worksheet
    Dim targetWS As Worksheet
    Dim lastRow As Long
    Dim targetLastRow As Long
    Dim i As Long
    
    ' Set references to your worksheets (update names if they change)
    Set sourceWS = ThisWorkbook.Worksheets("2")
    Set targetWS = ThisWorkbook.Worksheets("Core_Cutter_List")
    
    ' Speed up code by disabling screen updates
    Application.ScreenUpdating = False
    
    ' Find the last used row in column A of the source sheet
    lastRow = sourceWS.Cells(sourceWS.Rows.Count, "A").End(xlUp).Row
    
    ' Loop through each row in the source sheet
    For i = 1 To lastRow
        ' Check if column A has content AND column G is empty
        If sourceWS.Cells(i, "A").Value <> "" And sourceWS.Cells(i, "G").Value = "" Then
            ' Find the next blank row in the target sheet
            targetLastRow = targetWS.Cells(targetWS.Rows.Count, "A").End(xlUp).Row + 1
            
            ' Copy the entire row from source to target
            sourceWS.Rows(i).Copy Destination:=targetWS.Rows(targetLastRow)
            
            ' Optional: Mark the row as processed (uncomment to use)
            ' sourceWS.Cells(i, "G").Value = "Copied to Core List"
        End If
    Next i
    
    ' Re-enable screen updates
    Application.ScreenUpdating = True
    
    ' Let you know when it's done
    MsgBox "Success! Matching rows copied to Core_Cutter_List.", vbInformation
End Sub

Key Details & Customization

  • Worksheet References: Using ThisWorkbook.Worksheets ensures we're working with the current workbook, so you don't have to worry about accidentally targeting other open files.
  • Efficiency Toggle: Disabling ScreenUpdating makes the code run way faster without all the annoying screen flicker—we turn it back on at the end, always!
  • Row Validation: The check sourceWS.Cells(i, "A").Value <> "" And sourceWS.Cells(i, "G").Value = "" strictly enforces your criteria: only rows with text in A and nothing in G get copied.
  • Processed Row Marking: If you want to avoid copying the same row multiple times, uncomment the line that writes "Copied to Core List" into column G of the source sheet. This marks the row as handled so it won't get picked up in future runs.

How to Use This

  1. Open your Excel workbook and press Alt + F11 to open the VBA Editor.
  2. In the left-hand Project Explorer, right-click your workbook name and select Insert > Module.
  3. Paste the code into the new module window.
  4. Run the code by pressing F5, or go back to Excel and add a button to the ribbon/worksheet to trigger the macro with a click (great for non-VBA users!).

Quick Notes

  • Make sure the sheets "2" and "Core_Cutter_List" exist in your workbook—if their names change, update those strings in the code.
  • If your data starts at row 2 (with headers in row 1), adjust the loop to start at i = 2 instead of i = 1 to skip the header row.

内容的提问来源于stack exchange,提问作者Melnemac32

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:08:27