DocAElstein
Banned user
- Joined
- May 24, 2014
- Messages
- 1,336
Copy based on match criteria. Code Alternative to looping?
Hi, I need help in speeding up one of my simple Sort Codes…
.. I have had some success learning in sorting programs from participating in MrExcel Threads, but as a beginner I think my methods are still somewhat primitive (Mostly simple looping). One problem I find in my own project is that my looping method can take very long for some big files of mine.
. I have organized a much shortened version of one of my projects here with working codes of the type which take very long in my actual Files. These files are stripped down to the very minimum for clarity, so of course, are very fast.
. I would appreciate any code alternatives, mainly in the following directions:
. - I have ideas in the direction of filters , Advannced Filter Copy etc. (direct in VBA code or using the evaluate function within VBA to use some sort of spreadsheet filter function), but have no experience at all in this area and am attempting to learn that now. (Column B is free and available and could be used as a help column). Even if there are no speed alternatives I would also appreciate code alternatives to help me in learning different methods.
. So the example A
. This the first sheet in a Main Workbook, before the running of the macros:
. This is the first sheet of another file with entries to be included in the main file by the macros:
. This is how the first sheet in the main workbook looks after running the macros:
Here are the 2 files:
The main File with macros in it (In Module named “SortingMacros”);
XL 2007
FileSnack | Easy file sharing
XL2003
FileSnack | Easy file sharing
The file for entries to be included in the main File;
XL 2007
FileSnack | Easy file sharing
XL 2003
FileSnack | Easy file sharing
. Here are the codes again (XL 2007 versions) first simplified; . and a fuller version with some comments etc.
Code 1
<font face=Calibri><br><SPAN style="color:#00007F">Sub</SPAN> ProZuBlancoEingabe2() <SPAN style="color:#007F00">'Look for Name match and Entry in every row</SPAN><br><SPAN style="color:#007F00">'</SPAN><br>Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> Blanco <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, Pro <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> <SPAN style="color:#007F00">'File names</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Blanco = "MrExcelMainFileSorting2_2007.xlsm" <SPAN style="color:#007F00">'Test Main File for MrExcel</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Pro = "MrExcelFileWithEntries2_2007.xlsx" <SPAN style="color:#007F00">'Test File with Entries for MrExcel</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> wkstBlc <SPAN style="color:#00007F">As</SPAN> Worksheet, wkstPro <SPAN style="color:#00007F">As</SPAN> Worksheet <SPAN style="color:#007F00">'Main File Worksheet, File with Entries Worksheet</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstBlc = Workbooks(Blanco).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in Main File</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstPro = Workbooks(Pro).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in File with entries</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> CClmPPRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, CClmBlcoRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> <SPAN style="color:#007F00">'C Columns in Spreadsheets Row Count</SPAN><br><SPAN style="color:#007F00">'Main Program</SPAN><br><SPAN style="color:#007F00">'Strategy: Take each Row in turn in Blanco then look through each row in Pro for a name match in first column and an Entry in Pro column C. Then if a an entry is given in Pro Column C, copy that value to Blanco Column C</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmBlcoRow = 3 <SPAN style="color:#00007F">To</SPAN> 10 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'For each row in Blanco....</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmPPRow = 3 <SPAN style="color:#00007F">To</SPAN> 20 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'....Go through rows in Pro</SPAN><br> Application.StatusBar = "Blanco Row " & CClmBlcoRow & " Pro Row " & CClmPPRow <SPAN style="color:#007F00">'Can be ommited for speed but in large files is not usually the limiting factor</SPAN><br> <SPAN style="color:#00007F">If</SPAN> wkstBlc.Cells(CClmBlcoRow, 1).Value = wkstPro.Cells(CClmPPRow, 1).Value And wkstPro.Cells(CClmPPRow, 3).Value <> "" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'Check for name match and an Entry In Pro Column C</SPAN><br> <SPAN style="color:#00007F">Let</SPAN> wkstBlc.Cells(CClmBlcoRow, 3).Value = wkstPro.Cells(CClmPPRow, 3).Value <SPAN style="color:#007F00">'Match and Entry found so write entry value from Entry File in Main File</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'Else no match and entry so do nothhing!</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmPPRow <SPAN style="color:#007F00">'Go to next Pro Row..</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmBlcoRow <SPAN style="color:#007F00">'... when Pro row to end start again witn next row in Blanco</SPAN><br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>Application.StatusBar = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN> <SPAN style="color:#007F00">'ProZuBlancoEingabe2()</SPAN></FONT>
Code 2
<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> ProZuBlancoEingabe3() <SPAN style="color:#007F00">'look first only for C Column entry and then a match in Names</SPAN><br><SPAN style="color:#007F00">'</SPAN><br>Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> Blanco <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, Pro <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> <SPAN style="color:#007F00">'File names</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Blanco = "MrExcelMainFileSorting2_2007.xlsm" <SPAN style="color:#007F00">'Test Main File for MrExcel</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Pro = "MrExcelFileWithEntries2_2007.xlsx" <SPAN style="color:#007F00">'Test File with Entries for MrExcel</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> wkstBlc <SPAN style="color:#00007F">As</SPAN> Worksheet, wkstPro <SPAN style="color:#00007F">As</SPAN> Worksheet <SPAN style="color:#007F00">'Main File Worksheet, File with entries Worksheet</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstBlc = Workbooks(Blanco).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in main File</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstPro = Workbooks(Pro).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in File with entries</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> CClmPPRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, CClmBlcoRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> <SPAN style="color:#007F00">'C Columns in Spreadsheets Row Count</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> Match <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN> <SPAN style="color:#007F00">'Flag (Indicator) for match found = True for match or = False for no match found</SPAN><br><SPAN style="color:#007F00">'Main Program</SPAN><br><SPAN style="color:#007F00">'Strategy: look down C Column rows in Pro and when an entry is there loop through name columns in Blanco to find match in Names</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmPPRow = 3 <SPAN style="color:#00007F">To</SPAN> 20 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'look down C Column rows...</SPAN><br> <SPAN style="color:#00007F">If</SPAN> wkstPro.Cells(CClmPPRow, 3).Value <> "" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'....Look for entry in pro Column, If found....</SPAN><br> Match = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">'Match Found</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmBlcoRow = 3 <SPAN style="color:#00007F">To</SPAN> 10 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'For each Blanco C cell (or rather down the rows in Blanco)</SPAN><br> Application.StatusBar = "Blanco Row " & CClmBlcoRow & " Pro Row " & CClmPPRow <SPAN style="color:#007F00">'Can be ommited for speed but in large files is not usually the limiting factor</SPAN><br> <SPAN style="color:#00007F">If</SPAN> wkstBlc.Cells(CClmBlcoRow, 1).Value = wkstPro.Cells(CClmPPRow, 1).Value <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'Check for Name match</SPAN><br> <SPAN style="color:#00007F">Let</SPAN> wkstBlc.Cells(CClmBlcoRow, 3).Value = wkstPro.Cells(CClmPPRow, 3).Value <SPAN style="color:#007F00">'Match found so type in amount in Blanco</SPAN><br> <SPAN style="color:#00007F">Let</SPAN> Match = <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#007F00">'reset Match indicater for next loop</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'No Name match so do nothing</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmBlcoRow <SPAN style="color:#007F00">'look again for a match in next Blanco C Row.</SPAN><br> <SPAN style="color:#00007F">If</SPAN> Match = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'We have not reset Match to false so we had an entry but no match</SPAN><br> MsgBox "Entry in Pro for " & wkstPro.Cells(CClmPPRow, 1).Value & ". But no match in Blanco"<br> <SPAN style="color:#00007F">Let</SPAN> Match = <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#007F00">'The user is warned of entry but no match. So reset Match = False for next loop</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'Match is reset to false so match was found so do nothing (No warning MsgBox of no match)</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'Else do nothhing as no entry was found in Column c of Pro.</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmPPRow <SPAN style="color:#007F00">' go to next Row in C column of Pro and look for entry</SPAN><br> <SPAN style="color:#007F00">'</SPAN><br>TheEnd:<br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>Application.StatusBar = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN> <SPAN style="color:#007F00">'ProZuBlancoEingabe3()</SPAN></FONT>
Thanks,
Alan.
Hi, I need help in speeding up one of my simple Sort Codes…
.. I have had some success learning in sorting programs from participating in MrExcel Threads, but as a beginner I think my methods are still somewhat primitive (Mostly simple looping). One problem I find in my own project is that my looping method can take very long for some big files of mine.
. I have organized a much shortened version of one of my projects here with working codes of the type which take very long in my actual Files. These files are stripped down to the very minimum for clarity, so of course, are very fast.
. I would appreciate any code alternatives, mainly in the following directions:
. - I have ideas in the direction of filters , Advannced Filter Copy etc. (direct in VBA code or using the evaluate function within VBA to use some sort of spreadsheet filter function), but have no experience at all in this area and am attempting to learn that now. (Column B is free and available and could be used as a help column). Even if there are no speed alternatives I would also appreciate code alternatives to help me in learning different methods.
. So the example A
. This the first sheet in a Main Workbook, before the running of the macros:
Book1 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Produnt | ||||
2 | Name | ||||
3 | Chocolate-europe aroma | ||||
4 | Chocolate-Cookies | ||||
5 | Banana-Chocolate-Split | ||||
6 | Limette-Ksekuchen | ||||
7 | Erdbeere-Quark | ||||
8 | Erdbeere-Mix | ||||
9 | Jamaica Sun | ||||
10 | Waldbeeren | ||||
11 | |||||
12 | |||||
13 | |||||
Tabelle1 |
. This is the first sheet of another file with entries to be included in the main file by the macros:
Book1 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Product | ||||
2 | Name | ||||
3 | Haselnu-Walnu-aromatisiert | ||||
4 | Tiramisu | 2 | |||
5 | Chocolate-colonial blend | ||||
6 | Chocolate-europe aroma | 4 | |||
7 | Chocolate-Cookies | ||||
8 | Jamaica Sun | 6 | |||
9 | Himbeere-Joghurt | ||||
10 | Erdbeere-Quark | 8 | |||
11 | Erdbeere-Mix | ||||
12 | Banana-Chocolate-Split | 10 | |||
13 | Waldbeeren | ||||
14 | Kirsche | 12 | |||
15 | Kirsche-grner Apfel | ||||
16 | Kirsche-Ananas | 14 | |||
17 | Stracciatella | ||||
18 | Limette-Ksekuchen | 16 | |||
19 | grner Apfel-Quark | ||||
20 | Blutorange-Quark | ||||
21 | |||||
Pro |
. This is how the first sheet in the main workbook looks after running the macros:
Book1 | |||||
---|---|---|---|---|---|
A | B | C | |||
1 | Produnt | ||||
2 | Name | ||||
3 | Chocolate-europe aroma | 4 | |||
4 | Chocolate-Cookies | ||||
5 | Banana-Chocolate-Split | 10 | |||
6 | Limette-Ksekuchen | 16 | |||
7 | Erdbeere-Quark | 8 | |||
8 | Erdbeere-Mix | ||||
9 | Jamaica Sun | 6 | |||
10 | Waldbeeren | ||||
11 | |||||
12 | |||||
Tabelle1 |
Here are the 2 files:
The main File with macros in it (In Module named “SortingMacros”);
XL 2007
FileSnack | Easy file sharing
XL2003
FileSnack | Easy file sharing
The file for entries to be included in the main File;
XL 2007
FileSnack | Easy file sharing
XL 2003
FileSnack | Easy file sharing
. Here are the codes again (XL 2007 versions) first simplified; . and a fuller version with some comments etc.
Code 1
Code:
Sub ProZuBlancoEingabe2Simplified()
Application.ScreenUpdating = False
Dim Blanco As String, Pro As String
Let Blanco = "MrExcelMainFileSorting2_2007.xlsm"
Let Pro = "MrExcelFileWithEntries2_2007.xlsx"
Dim wkstBlc As Worksheet, wkstPro As Worksheet
Set wkstBlc = Workbooks(Blanco).Worksheets.Item(1)
Set wkstPro = Workbooks(Pro).Worksheets.Item(1)
Dim CClmPPRow As Long, CClmBlcoRow As Long
For CClmBlcoRow = 3 To 10 Step 1
For CClmPPRow = 3 To 20 Step 1
Application.StatusBar = "Blanco Row " & CClmBlcoRow & " Pro Row " & CClmPPRow
If wkstBlc.Cells(CClmBlcoRow, 1).Value = wkstPro.Cells(CClmPPRow, 1).Value And wkstPro.Cells(CClmPPRow, 3).Value <> "" Then
Let wkstBlc.Cells(CClmBlcoRow, 3).Value = wkstPro.Cells(CClmPPRow, 3).Value
Else
End If
Next CClmPPRow
Next CClmBlcoRow
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
<font face=Calibri><br><SPAN style="color:#00007F">Sub</SPAN> ProZuBlancoEingabe2() <SPAN style="color:#007F00">'Look for Name match and Entry in every row</SPAN><br><SPAN style="color:#007F00">'</SPAN><br>Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> Blanco <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, Pro <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> <SPAN style="color:#007F00">'File names</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Blanco = "MrExcelMainFileSorting2_2007.xlsm" <SPAN style="color:#007F00">'Test Main File for MrExcel</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Pro = "MrExcelFileWithEntries2_2007.xlsx" <SPAN style="color:#007F00">'Test File with Entries for MrExcel</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> wkstBlc <SPAN style="color:#00007F">As</SPAN> Worksheet, wkstPro <SPAN style="color:#00007F">As</SPAN> Worksheet <SPAN style="color:#007F00">'Main File Worksheet, File with Entries Worksheet</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstBlc = Workbooks(Blanco).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in Main File</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstPro = Workbooks(Pro).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in File with entries</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> CClmPPRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, CClmBlcoRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> <SPAN style="color:#007F00">'C Columns in Spreadsheets Row Count</SPAN><br><SPAN style="color:#007F00">'Main Program</SPAN><br><SPAN style="color:#007F00">'Strategy: Take each Row in turn in Blanco then look through each row in Pro for a name match in first column and an Entry in Pro column C. Then if a an entry is given in Pro Column C, copy that value to Blanco Column C</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmBlcoRow = 3 <SPAN style="color:#00007F">To</SPAN> 10 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'For each row in Blanco....</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmPPRow = 3 <SPAN style="color:#00007F">To</SPAN> 20 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'....Go through rows in Pro</SPAN><br> Application.StatusBar = "Blanco Row " & CClmBlcoRow & " Pro Row " & CClmPPRow <SPAN style="color:#007F00">'Can be ommited for speed but in large files is not usually the limiting factor</SPAN><br> <SPAN style="color:#00007F">If</SPAN> wkstBlc.Cells(CClmBlcoRow, 1).Value = wkstPro.Cells(CClmPPRow, 1).Value And wkstPro.Cells(CClmPPRow, 3).Value <> "" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'Check for name match and an Entry In Pro Column C</SPAN><br> <SPAN style="color:#00007F">Let</SPAN> wkstBlc.Cells(CClmBlcoRow, 3).Value = wkstPro.Cells(CClmPPRow, 3).Value <SPAN style="color:#007F00">'Match and Entry found so write entry value from Entry File in Main File</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'Else no match and entry so do nothhing!</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmPPRow <SPAN style="color:#007F00">'Go to next Pro Row..</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmBlcoRow <SPAN style="color:#007F00">'... when Pro row to end start again witn next row in Blanco</SPAN><br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>Application.StatusBar = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN> <SPAN style="color:#007F00">'ProZuBlancoEingabe2()</SPAN></FONT>
Code 2
Code:
Sub ProZuBlancoEingabe3Simplified()
Application.ScreenUpdating = False
Dim Blanco As String, Pro As String
Let Blanco = "MrExcelMainFileSorting2_2007.xlsm"
Let Pro = "MrExcelFileWithEntries2_2007.xlsx"
Dim wkstBlc As Worksheet, wkstPro As Worksheet
Set wkstBlc = Workbooks(Blanco).Worksheets.Item(1)
Set wkstPro = Workbooks(Pro).Worksheets.Item(1)
Dim CClmPPRow As Long, CClmBlcoRow As Long
Dim Match As Boolean
For CClmPPRow = 3 To 20 Step 1
If wkstPro.Cells(CClmPPRow, 3).Value <> "" Then
Match = True
For CClmBlcoRow = 3 To 10 Step 1
Application.StatusBar = "Blanco Row " & CClmBlcoRow & " Pro Row " & CClmPPRow
If wkstBlc.Cells(CClmBlcoRow, 1).Value = wkstPro.Cells(CClmPPRow, 1).Value Then
Let wkstBlc.Cells(CClmBlcoRow, 3).Value = wkstPro.Cells(CClmPPRow, 3).Value
Let Match = False
Else
End If
Next CClmBlcoRow
If Match = True Then
MsgBox "Entry in Pro for " & wkstPro.Cells(CClmPPRow, 1).Value & ". But no match in Blanco"
Let Match = False
Else
End If
Else
End If
Next CClmPPRow
TheEnd:
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> ProZuBlancoEingabe3() <SPAN style="color:#007F00">'look first only for C Column entry and then a match in Names</SPAN><br><SPAN style="color:#007F00">'</SPAN><br>Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> Blanco <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, Pro <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN> <SPAN style="color:#007F00">'File names</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Blanco = "MrExcelMainFileSorting2_2007.xlsm" <SPAN style="color:#007F00">'Test Main File for MrExcel</SPAN><br><SPAN style="color:#00007F">Let</SPAN> Pro = "MrExcelFileWithEntries2_2007.xlsx" <SPAN style="color:#007F00">'Test File with Entries for MrExcel</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> wkstBlc <SPAN style="color:#00007F">As</SPAN> Worksheet, wkstPro <SPAN style="color:#00007F">As</SPAN> Worksheet <SPAN style="color:#007F00">'Main File Worksheet, File with entries Worksheet</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstBlc = Workbooks(Blanco).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in main File</SPAN><br><SPAN style="color:#00007F">Set</SPAN> wkstPro = Workbooks(Pro).Worksheets.Item(1) <SPAN style="color:#007F00">'First sheet in File with entries</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> CClmPPRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, CClmBlcoRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN> <SPAN style="color:#007F00">'C Columns in Spreadsheets Row Count</SPAN><br><SPAN style="color:#00007F">Dim</SPAN> Match <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN> <SPAN style="color:#007F00">'Flag (Indicator) for match found = True for match or = False for no match found</SPAN><br><SPAN style="color:#007F00">'Main Program</SPAN><br><SPAN style="color:#007F00">'Strategy: look down C Column rows in Pro and when an entry is there loop through name columns in Blanco to find match in Names</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmPPRow = 3 <SPAN style="color:#00007F">To</SPAN> 20 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'look down C Column rows...</SPAN><br> <SPAN style="color:#00007F">If</SPAN> wkstPro.Cells(CClmPPRow, 3).Value <> "" <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'....Look for entry in pro Column, If found....</SPAN><br> Match = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#007F00">'Match Found</SPAN><br> <SPAN style="color:#00007F">For</SPAN> CClmBlcoRow = 3 <SPAN style="color:#00007F">To</SPAN> 10 <SPAN style="color:#00007F">Step</SPAN> 1 <SPAN style="color:#007F00">'For each Blanco C cell (or rather down the rows in Blanco)</SPAN><br> Application.StatusBar = "Blanco Row " & CClmBlcoRow & " Pro Row " & CClmPPRow <SPAN style="color:#007F00">'Can be ommited for speed but in large files is not usually the limiting factor</SPAN><br> <SPAN style="color:#00007F">If</SPAN> wkstBlc.Cells(CClmBlcoRow, 1).Value = wkstPro.Cells(CClmPPRow, 1).Value <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'Check for Name match</SPAN><br> <SPAN style="color:#00007F">Let</SPAN> wkstBlc.Cells(CClmBlcoRow, 3).Value = wkstPro.Cells(CClmPPRow, 3).Value <SPAN style="color:#007F00">'Match found so type in amount in Blanco</SPAN><br> <SPAN style="color:#00007F">Let</SPAN> Match = <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#007F00">'reset Match indicater for next loop</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'No Name match so do nothing</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmBlcoRow <SPAN style="color:#007F00">'look again for a match in next Blanco C Row.</SPAN><br> <SPAN style="color:#00007F">If</SPAN> Match = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#007F00">'We have not reset Match to false so we had an entry but no match</SPAN><br> MsgBox "Entry in Pro for " & wkstPro.Cells(CClmPPRow, 1).Value & ". But no match in Blanco"<br> <SPAN style="color:#00007F">Let</SPAN> Match = <SPAN style="color:#00007F">False</SPAN> <SPAN style="color:#007F00">'The user is warned of entry but no match. So reset Match = False for next loop</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'Match is reset to false so match was found so do nothing (No warning MsgBox of no match)</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Else</SPAN> <SPAN style="color:#007F00">'Else do nothhing as no entry was found in Column c of Pro.</SPAN><br> <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br> <SPAN style="color:#00007F">Next</SPAN> CClmPPRow <SPAN style="color:#007F00">' go to next Row in C column of Pro and look for entry</SPAN><br> <SPAN style="color:#007F00">'</SPAN><br>TheEnd:<br>Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br>Application.StatusBar = <SPAN style="color:#00007F">False</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN> <SPAN style="color:#007F00">'ProZuBlancoEingabe3()</SPAN></FONT>
Thanks,
Alan.