parkerbelt
Active Member
- Joined
- May 23, 2014
- Messages
- 377
I have an Excel workbook that has a sheet that has a list of 500 stores numbered Store number 1, store number 7 store number 11, etc.. - these are my test stores. The store number is in column A. I'm calling this sheet "500 Test Stores". The sheet doesn't contain duplicate store numbers, it is an index if you will.
I have another Excel workbook that has a large list of store data, which includes store number in column A along with Sales data in a different column and Quantity on-hand in another column, and other data in other columns, etc.. I'm calling this sheet "Test Dump". This sheet contains multiple store numbers that are the same, because the data goes with different items that are sold at the same store.
I'm trying to write a program that will look at each cell in column A of the 500 Test Stores sheet and look for a match in the Test Dump sheet and if it finds a match, copy the row of data where the match is and paste it into a different tab that I call "Test Stores Data".
If the store number doesn't match, I want to copy the row of data into a tab called "All Other Stores Data".
I'm a bit inexperienced and rusty - and each time I try to create my loops, I keep duplicating data and the program is really in-efficient.
Does anyone know how to write the code so that my loop is efficient, it sorts the data like I want it to and it doesn't duplicate any data?
Here's what I've attempted, but it is going to duplicate data if allowed to run through:
I have another Excel workbook that has a large list of store data, which includes store number in column A along with Sales data in a different column and Quantity on-hand in another column, and other data in other columns, etc.. I'm calling this sheet "Test Dump". This sheet contains multiple store numbers that are the same, because the data goes with different items that are sold at the same store.
I'm trying to write a program that will look at each cell in column A of the 500 Test Stores sheet and look for a match in the Test Dump sheet and if it finds a match, copy the row of data where the match is and paste it into a different tab that I call "Test Stores Data".
If the store number doesn't match, I want to copy the row of data into a tab called "All Other Stores Data".
I'm a bit inexperienced and rusty - and each time I try to create my loops, I keep duplicating data and the program is really in-efficient.
Does anyone know how to write the code so that my loop is efficient, it sorts the data like I want it to and it doesn't duplicate any data?
Here's what I've attempted, but it is going to duplicate data if allowed to run through:
HTML:
Dim SearchStore As LongDim lastrow500 As LongDim lastrow As Long Sheets("500 Test Stores").Select lastrow500 = Cells(Rows.Count, "A").End(xlUp).Row Sheets("Temp Dump").Select lastrow = Cells(Rows.Count, "A").End(xlUp).Row Dim i As Long i = 2
Dim its As Long its = 2
Dim iao As Long
iao = 2
Dim itsl As Long itsl = 2
' Start of loop for Test Stores
Do Until itsl = lastrow500 + 1
Sheets("500 Test Stores").Select
SearchStore = Range("A" & its).Value.Select
Do Until i = lastrow + 1
Sheets("Temp Dump").Select Range("A" & i).Select
If Range("A" & i).Value = SearchStore Then Rows(ActiveCell.Row).Select Selection.Copy Sheets("Test Stores Data").Select Range("A" & i).Select ActiveSheet.Paste i = i + 1 its = its + 1 Else Rows(ActiveCell.Row).Select Selection.Copy Sheets("All Other Stores Data").Select Range("A" & iao).Select ActiveSheet.Paste iao = iao + 1 i = i + 1 End If Loop
itsl = itsl + 1 Loop