Loop through VBA

lalro143

New Member
Joined
May 30, 2014
Messages
39
Hi,

I have two sheets. One having warehouse(18 warehouse) and second having shop (50 Shops).

I need to map shops against warehouse within 200 KM.

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.
Then one formula in the sheet (already updated in shop sheet) calculate the difference in KM between each shop and first warehouse. Then filtered out shops within 200 km, copy and paste (transpose) against first warehouse in warehouse sheet. 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


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

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,293
Your quote
Now I want to do same procedure for second warehouse then third till end. Please help

Does each warehouse have a different sheet row or column.
Show us how the script would look when doing the second Warehouse versus the first warehouse.
 

lalro143

New Member
Joined
May 30, 2014
Messages
39
No all warehouse in only one sheet. Starts from cell c2 (lat) and cell d2 (lng)
below code copied first one which is in range(c2:d2) and pasted it to shop sheet to range (f2:g4175)
I dont know how to do it for next warehouse which is in c3:d3 cell till end of warehouses
===============
Worksheets("SHOP").Activate
AutoFilterMode = False
Range("f2:g4175").Clear
Worksheets("WAREHOUSE").Activate
Range("C2:d2").Select
Selection.Copy
=======================



 

lalro143

New Member
Joined
May 30, 2014
Messages
39
I have tried to do while loop but it showing some error


Sub RADIUS()
'Application.Workbooks.Open("D:\Current Reports & Updation\Lat Lng\All Petrol Pump\15KM DISTANCE.xlsx").Activate
'Application.Calculation = xlCalculateManual


Dim j As Integer
j = 2
Do While Worksheets("PP").Range("C" & j) <> ""


'Worksheets("PP").Activate
Range("C2:d2").Select
Selection.Copy


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


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


Worksheets("pp").Activate


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


Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
Worksheets("SITE").Activate
AutoFilterMode = False
Range("f2:g4175").Clear


j = j + 1
Loop
End Sub
 

Forum statistics

Threads
1,082,342
Messages
5,364,783
Members
400,815
Latest member
gangstar67

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top