Recognize values then populate up to 10 new rows

Kreiz

New Member
Joined
May 6, 2011
Messages
38
Greetings...

This site has done wonders for many of old friends who I've lost all touch with once they've found bigger paying jobs :D

I have a daily report of tracking information that i am needing to modify as rapid as possible. I need excel to recognize values in two columns and create 6-10 new columns in the same sheet or a new sheet with populated information.

eg..

*date*mile*beginCITY*beginSTATE*finalCITY*finalSTATE*size*time*who*what*

As the program recognizes a specific value for *beginCITY*beginSTATE* column as *Chicago*IL* I need it to create 3-5 new rows with all the same data but preset cities/states for that determined *Chicago*IL* and then do the same for *finalCITY*finalSTATE* 3-5 new rows only the city and state will change to the predetermined "outer cities/states"

Can anybody think of a way to start as i will be continuously be adding data for the city and state ranges (ie everytime it sees a Chicago IL it will make new row for 3-5 predetermined values i set)

Thank you for your time,
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Kreiz,

I assume that the codes in Sheet1 in column A are a standard location code for you industry. Is that so?

You will have to build a table in Sheet1 similar to this:


Excel Workbook
ABCDEFGH
1Origin-CityOr-StDest-CityDe-StFCL to OAKFORT COLLINS CO|OAKLAND CA
2FCL to OAKFCL to GRNTFORT COLLINS CO|GRANITE CITY IL
3DENVERCOOAKLANDCAFCL to SDIEFORT COLLINS CO|SAN DIEGO CA
4SIDNEYNEOAKLANDCA
5COLBYKSOAKLANDCA
6PUEBLOCOOAKLANDCA
7CHEYENNEWYOAKLANDCA
8FORT COLLINSCOFRESNOCA
9FORT COLLINSCOSAN FRANCISCOCA
10FORT COLLINSCOSACRAMENTOCA
11FORT COLLINSCOSTOCKTONCA
12FORT COLLINSCOYUBA CITYCA
13FCL to GRNT
14DENVERCOGRANITE CITYIL
15SIDNEYNEGRANITE CITYIL
16COLBYKSGRANITE CITYIL
17PUEBLOCOGRANITE CITYIL
18CHEYENNEWYGRANITE CITYIL
19FORT COLLINSCOST LOUISMO
20FORT COLLINSCOCAPE GIRARDEAUMO
21FORT COLLINSCOQUINCYIL
22FORT COLLINSCOSPRINGFIELDIL
23FORT COLLINSCOEVANSVILLEIN
24FORT COLLINSCOKANSAS CITYMO
25FCL to SDIE
26DENVERCOSAN DIEGOCA
27SIDNEYNESAN DIEGOCA
28COLBYKSSAN DIEGOCA
29PUEBLOCOSAN DIEGOCA
30CHEYENNEWYSAN DIEGOCA
31FORT COLLINSCOIMPERIALCA
32FORT COLLINSCOOCEANSIDECA
33FORT COLLINSCORIVERSIDECA
34FORT COLLINSCOYUMAAZ
35FORT COLLINSCOBLYTHECA
36
Sheet1




The above information in columns G and H will make it so that we can search for information and insert that data in columns B thru E into Sheet2.

We first copy the raw downloaded data from Sheet3 into Sheet 2, and add column L:

Excel Workbook
ABCDEFGHIJKL
1AvailTruckOrigin-CityOr-StOr-ZipDest-CityDe-StDe-ZipF/PFt.kLbs
25/7/2011RFORT COLLINSCOOAKLANDCAFull5344FORT COLLINS CO|OAKLAND CA
35/7/2011RFORT COLLINSCOGRANITE CITYILFull5344FORT COLLINS CO|GRANITE CITY IL
45/7/2011RFORT COLLINSCOSAN DIEGOCAFull5344FORT COLLINS CO|SAN DIEGO CA
5
Sheet2




I can now seatch column L for a match in Sheet1 column G to find the group in column A, and insert rows in Sheet2, and copy the group data from Sheet1 columns B thru E.

Does this sound feasable?









Right now there is no correlation between the data table in worksheet Sheet1
 
Upvote 0
Somewhat, the matching and searching setup i believe I understand.

I am trying to add rows not columns. As sheet 2 is the raw data downloaded, I am looking to make those 3 orders (sheet2 row2:3 A:K) turn into many many more. The kicker is that I have 50-80 different orders(rows) of raw data so you add 5-10 orders(rows) we will have 250-800 orders creatively made.
 
Upvote 0
Kreiz,

I assume that the codes in Sheet1 in column A are a standard location code for you industry. Is that so?


As sheet 2 is the raw data downloaded

OK, you do not need a Sheet3.


Right now there is no correlation between the data table in worksheet Sheet1 and the raw data downloaded in Sheet2.

I am trying to explain that I will need another table in Sheet1 columns G and K, so that I can find the correct groups in column A.
 
Upvote 0
Kreiz,

Without the additional table in Sheet1 columns G and H, I can not do what you are asking.

Nowhere in your workbook is there a way to search for, or understand that:
FCL to OAK

stands for:

Excel Workbook
CDEFG
2FORT COLLINSCOOAKLANDCA
Sheet2
 
Upvote 0
The FCL to OAK is only for my reference, I believe I will have to create a different database. Not sure though on how to start that with out knowing how excel is going to relate or pair 4 columns once it realizes it is one in the database of creative lanes.
 
Upvote 0
Kreiz,

You have not setteled on what worksheet Sheet1 will look like, so, what follows is a workable solution.

I have changed what column A on worksheet Sheet1 looks like:


Sample worksheets before the macro:


Excel Workbook
ABCDE
1Origin-CityOr-StDest-CityDe-St
2FORT COLLINS CO | OAKLAND CA
3DENVERCOOAKLANDCA
4SIDNEYNEOAKLANDCA
5COLBYKSOAKLANDCA
6PUEBLOCOOAKLANDCA
7CHEYENNEWYOAKLANDCA
8FORT COLLINSCOFRESNOCA
9FORT COLLINSCOSAN FRANCISCOCA
10FORT COLLINSCOSACRAMENTOCA
11FORT COLLINSCOSTOCKTONCA
12FORT COLLINSCOYUBA CITYCA
13FORT COLLINS CO | GRANITE CITY IL
14DENVERCOGRANITE CITYIL
15SIDNEYNEGRANITE CITYIL
16COLBYKSGRANITE CITYIL
17PUEBLOCOGRANITE CITYIL
18CHEYENNEWYGRANITE CITYIL
19FORT COLLINSCOST LOUISMO
20FORT COLLINSCOCAPE GIRARDEAUMO
21FORT COLLINSCOQUINCYIL
22FORT COLLINSCOSPRINGFIELDIL
23FORT COLLINSCOEVANSVILLEIN
24FORT COLLINSCOKANSAS CITYMO
25FORT COLLINS CO | SAN DIEGO CA
26DENVERCOSAN DIEGOCA
27SIDNEYNESAN DIEGOCA
28COLBYKSSAN DIEGOCA
29PUEBLOCOSAN DIEGOCA
30CHEYENNEWYSAN DIEGOCA
31FORT COLLINSCOIMPERIALCA
32FORT COLLINSCOOCEANSIDECA
33FORT COLLINSCORIVERSIDECA
34FORT COLLINSCOYUMAAZ
35FORT COLLINSCOBLYTHECA
36
Sheet1





Excel Workbook
ABCDEFGHIJK
1AvailTruckOrigin-CityOr-StOr-ZipDest-CityDe-StDe-ZipF/PFt.kLbs
25/7/2011RFORT COLLINSCOOAKLANDCAFull5344
35/7/2011RFORT COLLINSCOGRANITE CITYILFull5344
45/7/2011RFORT COLLINSCOSAN DIEGOCAFull5344
5
Sheet2





After the macro on worksheet Sheet2:


Excel Workbook
ABCDEFGHIJK
1AvailTruckOrigin-CityOr-StOr-ZipDest-CityDe-StDe-ZipF/PFt.kLbs
25/7/2011RFORT COLLINSCOOAKLANDCAFull5344
35/7/2011RDENVERCOOAKLANDCAFull5344
45/7/2011RSIDNEYNEOAKLANDCAFull5344
55/7/2011RCOLBYKSOAKLANDCAFull5344
65/7/2011RPUEBLOCOOAKLANDCAFull5344
75/7/2011RCHEYENNEWYOAKLANDCAFull5344
85/7/2011RFORT COLLINSCOFRESNOCAFull5344
95/7/2011RFORT COLLINSCOSAN FRANCISCOCAFull5344
105/7/2011RFORT COLLINSCOSACRAMENTOCAFull5344
115/7/2011RFORT COLLINSCOSTOCKTONCAFull5344
125/7/2011RFORT COLLINSCOYUBA CITYCAFull5344
135/7/2011RFORT COLLINSCOGRANITE CITYILFull5344
145/7/2011RDENVERCOGRANITE CITYILFull5344
155/7/2011RSIDNEYNEGRANITE CITYILFull5344
165/7/2011RCOLBYKSGRANITE CITYILFull5344
175/7/2011RPUEBLOCOGRANITE CITYILFull5344
185/7/2011RCHEYENNEWYGRANITE CITYILFull5344
195/7/2011RFORT COLLINSCOST LOUISMOFull5344
205/7/2011RFORT COLLINSCOCAPE GIRARDEAUMOFull5344
215/7/2011RFORT COLLINSCOQUINCYILFull5344
225/7/2011RFORT COLLINSCOSPRINGFIELDILFull5344
235/7/2011RFORT COLLINSCOEVANSVILLEINFull5344
245/7/2011RFORT COLLINSCOKANSAS CITYMOFull5344
255/7/2011RFORT COLLINSCOSAN DIEGOCAFull5344
265/7/2011RDENVERCOSAN DIEGOCAFull5344
275/7/2011RSIDNEYNESAN DIEGOCAFull5344
285/7/2011RCOLBYKSSAN DIEGOCAFull5344
295/7/2011RPUEBLOCOSAN DIEGOCAFull5344
305/7/2011RCHEYENNEWYSAN DIEGOCAFull5344
315/7/2011RFORT COLLINSCOIMPERIALCAFull5344
325/7/2011RFORT COLLINSCOOCEANSIDECAFull5344
335/7/2011RFORT COLLINSCORIVERSIDECAFull5344
345/7/2011RFORT COLLINSCOYUMAAZFull5344
355/7/2011RFORT COLLINSCOBLYTHECAFull5344
36
Sheet2





If we change the number of rows for the groups on worksheet Sheet1:


Excel Workbook
ABCDE
1Origin-CityOr-StDest-CityDe-St
2FORT COLLINS CO | OAKLAND CA
3DENVERCOOAKLANDCA
4SIDNEYNEOAKLANDCA
5COLBYKSOAKLANDCA
6PUEBLOCOOAKLANDCA
7FORT COLLINS CO | GRANITE CITY IL
8DENVERCOGRANITE CITYIL
9SIDNEYNEGRANITE CITYIL
10COLBYKSGRANITE CITYIL
11PUEBLOCOGRANITE CITYIL
12CHEYENNEWYGRANITE CITYIL
13FORT COLLINSCOST LOUISMO
14FORT COLLINSCOCAPE GIRARDEAUMO
15FORT COLLINS CO | SAN DIEGO CA
16DENVERCOSAN DIEGOCA
17SIDNEYNESAN DIEGOCA
18COLBYKSSAN DIEGOCA
19
Sheet1





Worksheet Sheet2 before the macro:


Excel Workbook
ABCDEFGHIJK
1AvailTruckOrigin-CityOr-StOr-ZipDest-CityDe-StDe-ZipF/PFt.kLbs
25/7/2011RFORT COLLINSCOOAKLANDCAFull5344
35/7/2011RFORT COLLINSCOGRANITE CITYILFull5344
45/7/2011RFORT COLLINSCOSAN DIEGOCAFull5344
5
Sheet2





After the macro on worksheet Sheet2:


Excel Workbook
ABCDEFGHIJK
1AvailTruckOrigin-CityOr-StOr-ZipDest-CityDe-StDe-ZipF/PFt.kLbs
25/7/2011RFORT COLLINSCOOAKLANDCAFull5344
35/7/2011RDENVERCOOAKLANDCAFull5344
45/7/2011RSIDNEYNEOAKLANDCAFull5344
55/7/2011RCOLBYKSOAKLANDCAFull5344
65/7/2011RPUEBLOCOOAKLANDCAFull5344
75/7/2011RFORT COLLINSCOGRANITE CITYILFull5344
85/7/2011RDENVERCOGRANITE CITYILFull5344
95/7/2011RSIDNEYNEGRANITE CITYILFull5344
105/7/2011RCOLBYKSGRANITE CITYILFull5344
115/7/2011RPUEBLOCOGRANITE CITYILFull5344
125/7/2011RCHEYENNEWYGRANITE CITYILFull5344
135/7/2011RFORT COLLINSCOST LOUISMOFull5344
145/7/2011RFORT COLLINSCOCAPE GIRARDEAUMOFull5344
155/7/2011RFORT COLLINSCOSAN DIEGOCAFull5344
165/7/2011RDENVERCOSAN DIEGOCAFull5344
175/7/2011RSIDNEYNESAN DIEGOCAFull5344
185/7/2011RCOLBYKSSAN DIEGOCAFull5344
19
Sheet2




The BOLD and RED text is used to just show how the results would look.



Is the above acceptable to you? Would you like to try the macro after you make the changes to column A on worksheet Sheet1?
 
Upvote 0
This is exactly what I have been looking for. Worksheet 1 will be populated with all of the many differant lanes we service on a regular basis and I love how you were able to remove rows and the macro still adjusts and only places that many. How does it work!?! and what is the macro.
 
Upvote 0
Kreiz,


I was trying to find a way that I could search Sheet2 data against Sheet1 information.

Column L displays a formula that creates the search information:

Excel Workbook
ABCDEFGHIJKL
1AvailTruckOrigin-CityOr-StOr-ZipDest-CityDe-StDe-ZipF/PFt.kLbs
25/7/2011RFORT COLLINSCOOAKLANDCAFull5344FORT COLLINS CO | OAKLAND CA
35/7/2011RFORT COLLINSCOGRANITE CITYILFull5344FORT COLLINS CO | GRANITE CITY IL
45/7/2011RFORT COLLINSCOSAN DIEGOCAFull5344FORT COLLINS CO | SAN DIEGO CA
5
Sheet2




So I then changed what was on Sheet1, column A, from this:


Excel Workbook
ABCDE
1Origin-CityOr-StDest-CityDe-St
2FCL to OAK
3DENVERCOOAKLANDCA
4SIDNEYNEOAKLANDCA
5COLBYKSOAKLANDCA
6PUEBLOCOOAKLANDCA
7CHEYENNEWYOAKLANDCA
8FORT COLLINSCOFRESNOCA
9FORT COLLINSCOSAN FRANCISCOCA
10FORT COLLINSCOSACRAMENTOCA
11FORT COLLINSCOSTOCKTONCA
12FORT COLLINSCOYUBA CITYCA
13FCL to GRNT
14DENVERCOGRANITE CITYIL
15SIDNEYNEGRANITE CITYIL
16COLBYKSGRANITE CITYIL
17PUEBLOCOGRANITE CITYIL
18CHEYENNEWYGRANITE CITYIL
19FORT COLLINSCOST LOUISMO
20FORT COLLINSCOCAPE GIRARDEAUMO
21FORT COLLINSCOQUINCYIL
22FORT COLLINSCOSPRINGFIELDIL
23FORT COLLINSCOEVANSVILLEIN
24FORT COLLINSCOKANSAS CITYMO
25FCL to SDIE
26DENVERCOSAN DIEGOCA
27SIDNEYNESAN DIEGOCA
28COLBYKSSAN DIEGOCA
29PUEBLOCOSAN DIEGOCA
30CHEYENNEWYSAN DIEGOCA
31FORT COLLINSCOIMPERIALCA
32FORT COLLINSCOOCEANSIDECA
33FORT COLLINSCORIVERSIDECA
34FORT COLLINSCOYUMAAZ
35FORT COLLINSCOBLYTHECA
36
Sheet1





To this:


Excel Workbook
ABCDE
1Origin-CityOr-StDest-CityDe-St
2FORT COLLINS CO | OAKLAND CA
3DENVERCOOAKLANDCA
4SIDNEYNEOAKLANDCA
5COLBYKSOAKLANDCA
6PUEBLOCOOAKLANDCA
7CHEYENNEWYOAKLANDCA
8FORT COLLINSCOFRESNOCA
9FORT COLLINSCOSAN FRANCISCOCA
10FORT COLLINSCOSACRAMENTOCA
11FORT COLLINSCOSTOCKTONCA
12FORT COLLINSCOYUBA CITYCA
13FORT COLLINS CO | GRANITE CITY IL
14DENVERCOGRANITE CITYIL
15SIDNEYNEGRANITE CITYIL
16COLBYKSGRANITE CITYIL
17PUEBLOCOGRANITE CITYIL
18CHEYENNEWYGRANITE CITYIL
19FORT COLLINSCOST LOUISMO
20FORT COLLINSCOCAPE GIRARDEAUMO
21FORT COLLINSCOQUINCYIL
22FORT COLLINSCOSPRINGFIELDIL
23FORT COLLINSCOEVANSVILLEIN
24FORT COLLINSCOKANSAS CITYMO
25FORT COLLINS CO | SAN DIEGO CA
26DENVERCOSAN DIEGOCA
27SIDNEYNESAN DIEGOCA
28COLBYKSSAN DIEGOCA
29PUEBLOCOSAN DIEGOCA
30CHEYENNEWYSAN DIEGOCA
31FORT COLLINSCOIMPERIALCA
32FORT COLLINSCOOCEANSIDECA
33FORT COLLINSCORIVERSIDECA
34FORT COLLINSCOYUMAAZ
35FORT COLLINSCOBLYTHECA
36
Sheet1
 
Upvote 0
Kreiz,


You will have to manually change all the information in Sheet1, column A, to what I have done (information and format).


After you do the above, then you can test your new route information in Sheet1 against Sheet2.



Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 08/11/2011
' http://www.mrexcel.com/forum/showthread.php?t=548474
Dim w1 As Worksheet, w2 As Worksheet
Dim LR As Long, a As Long, FR As Long, SR As Long, ER As Long
Application.ScreenUpdating = True
Set w1 = Worksheets("Sheet1")
Set w2 = Worksheets("Sheet2")
w2.Columns(12).ClearContents
LR = w2.Cells(Rows.Count, 1).End(xlUp).Row
With w2.Range("L2:L" & LR)
  .FormulaR1C1 = "=RC[-9]&"" ""&RC[-8]&"" | ""&RC[-6]& "" ""&RC[-5]"
  .Value = .Value
End With
For a = LR To 2 Step -1
  FR = 0
  On Error Resume Next
  FR = Application.Match(w2.Range("L" & a), w1.Columns(1), 0)
  On Error GoTo 0
  If FR <> 0 Then
    SR = FR + 1
    ER = w1.Range("B" & SR).End(xlDown).Row
    w2.Rows(a).Offset(1).Resize(ER - SR + 1).Insert
    w2.Rows(a).Copy w2.Rows(a).Offset(1).Resize(ER - SR + 1)
    Application.DisplayAlerts = False
    w1.Range("B" & SR & ":C" & ER).Copy w2.Range("C" & a + 1).Resize(ER - SR, 2)
    Application.DisplayAlerts = False
    w1.Range("D" & SR & ":E" & ER).Copy w2.Range("F" & a + 1).Resize(ER - SR, 2)
  End If
Next a
w2.Columns(12).ClearContents
w2.Activate
Application.ScreenUpdating = False
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the ReorgData macro.
 
Upvote 0

Forum statistics

Threads
1,224,534
Messages
6,179,391
Members
452,909
Latest member
VickiS

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top