【问题标题】:loop through VBA to repeat the process循环通过 VBA 重复该过程
【发布时间】:2016-04-26 09:32:57
【问题描述】:

我有两张床单。一有仓库(18个仓库),二有店铺(50个店铺)。

我需要在 200 公里范围内将商店与仓库映射。

我已经为相同的代码编写了一个代码,但需要循环它。代码在下面提到

代码将从仓库表中复制第一个仓库并将其粘贴到商店表中的所有 50 家商店中。 然后工作表中的一个公式(已在车间工作表中更新)计算每个车间和第一个仓库之间的 KM 差异。然后过滤掉200公里内的店铺,对仓库表中的第一个仓库进行复制粘贴(转置)。现在我想对第二个仓库做同样的程序,然后是第三个仓库。请帮忙

===================================

Sub RADIUS()


Worksheets("SHOP").Activate
AutoFilterMode = False
Range("f2:g4175").Clear
Worksheets("WAREHOUSE").Activate
Range("C2:d2").Select
Selection.Copy


Worksheets("SHOP").Activate
Range("f2:g4175").PasteSpecial _
Operation:=xlPasteSpecialOperationAdd
Application.Calculation = xlCalculationAutomatic


AutoFilterMode = True
Range("A1:h1").AutoFilter Field:=8, Criteria1:="<=200"
Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy _


Worksheets("WAREHOUSE").Activate


Range("e" & Rows.Count).End(xlUp).Offset(1).Select


Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True


End Sub

【问题讨论】:

    标签: excel for-loop vba


    【解决方案1】:

    我建议在子声明之后,我将包括以下内容:

    j = 2
    While Worksheet("Warehouse").Range("C"&j) <> "" then
    

    在循环结束时,就在 End Sub 的上方,我将包括以下内容:

    j = j + 1
    Wend
    

    【讨论】:

    • Dim j As Integer j = 2 While Worksheets("PP").Range("C" & j) "" then ===compile error: syntex error===
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2015-09-05
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多