简体   繁体   English

遍历VBA以重复该过程

[英]loop through VBA to repeat the process

I have two sheets. 我有两张。 One having warehouse(18 warehouse) and second having shop (50 Shops). 一个有仓库(18个仓库),第二个有商店(50个商店)。

I need to map shops against warehouse within 200 KM. 我需要将商店映射到200公里以内的仓库。

I have written one code for the same but need to loop it. 我已经为相同的代码编写了一个代码,但是需要对其进行循环。 Code is mentioned below 代码如下

Code will copy first warehouse from warehouse sheet and paste it against each all 50 shops in shop sheet. 代码将从仓库表中复制第一个仓库,并将其粘贴到车间表中的所有50个商店中。 Then one formula in the sheet (already updated in shop sheet) calculate the difference in KM between each shop and first warehouse. 然后,工作表中的一个公式(已经在车间工作表中更新)计算每个车间和第一个仓库之间的KM差。 Then filtered out shops within 200 km, copy and paste (transpose) against first warehouse in warehouse sheet. 然后过滤掉200公里以内的商店,将其复制并粘贴(换位)到仓库表中的第一个仓库。 Now I want to do same procedure for second warehouse then third till end. 现在,我想对第二个仓库执行相同的步骤,然后对第三个仓库进行处理。 Please help 请帮忙

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

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

I would suggest that after the sub declaration, I would include the following: 我建议在子声明之后,添加以下内容:

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

At the end of the loop, just above the End Sub, I would include the following: 在循环的最后,在End Sub的上方,我将包括以下内容:

j = j + 1
Wend

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM