Jerry L
asked on
Excel: Sort & Match Rows - Must Handle Two Sets of Data Stacked in One Column
I had this code written in this post:
https://www.experts-exchange.com/questions/25192346/Excel-Match-Rows-Macro-Not-Working.html
(See attached file for the code and sample data.)
Here's the previous specification
-------------------------- ---------- ------
Sub MatchEm_9()
' Assumes that the two sets of data are in parallel columns. No data is to the right of the second set. _
The two sets of data must start in the same row, but need not contain the same data types, or number of columns. _
Nothing should be underneath either set of data. Blank row in the data set with the most rows terminates execution.
' The "key" must be the first column in each set of data
' The number of columns in each list is determined by looking to the right for a blank cell.
' Make sure all blank cells of the first rows are filled in with "dummy" values.
New specification to be as follows
-------------------------- ---------- --------
Sub MatchEm_10()
' The two sets of data must be separated by at least one blank row if Stacked one on top of the other
' or by one blank column if the data sets are next to one another.
' Each of the two data sets may contain a different number of columns and rows.
' The Max number of columns in each set is determined by a Blank Cell in the first row of each set.
' User MUST make sure all blank cells of the first row of each data set are filled in with "dummy" values so all columns of data will be included before a blank cell is reached.
' Data Set 1 ends when a Blank Cell in it's first column is parsed.
' Data Set 2 ends when a Blank Cell in it's first column is parsed.
' Both data sets must be parsed completely.
' The program allows the user to select the first cell in the first row in each set of data.
The code should work even when one set of data is directly below the other as long as there is a blank row between them.
Below, in the code window, is the way the results should look, and it works fine when the second set of data starts in a completely different group of columns from the first set of data, as specified by the original spec. (Paste it into a sheet to see it formatted properly.)
In the attached file, Sheet1 gives the layout of data I want the code to work with.
Sheet2 shows the data in a format that works with the current macro, matchem_9()
The file also contains the current version of the code.
Try it first with set 1 as the first selection, and set 2 as the second selection. But, you should be able to use any set of data (1, 2, or 3) as the first selection, and any other as the second selection. If set 2 is selected first, then either 1 or 3 could be the second set, for example.
https://www.experts-exchange.com/questions/25192346/Excel-Match-Rows-Macro-Not-Working.html
(See attached file for the code and sample data.)
Here's the previous specification
--------------------------
Sub MatchEm_9()
' Assumes that the two sets of data are in parallel columns. No data is to the right of the second set. _
The two sets of data must start in the same row, but need not contain the same data types, or number of columns. _
Nothing should be underneath either set of data. Blank row in the data set with the most rows terminates execution.
' The "key" must be the first column in each set of data
' The number of columns in each list is determined by looking to the right for a blank cell.
' Make sure all blank cells of the first rows are filled in with "dummy" values.
New specification to be as follows
--------------------------
Sub MatchEm_10()
' The two sets of data must be separated by at least one blank row if Stacked one on top of the other
' or by one blank column if the data sets are next to one another.
' Each of the two data sets may contain a different number of columns and rows.
' The Max number of columns in each set is determined by a Blank Cell in the first row of each set.
' User MUST make sure all blank cells of the first row of each data set are filled in with "dummy" values so all columns of data will be included before a blank cell is reached.
' Data Set 1 ends when a Blank Cell in it's first column is parsed.
' Data Set 2 ends when a Blank Cell in it's first column is parsed.
' Both data sets must be parsed completely.
' The program allows the user to select the first cell in the first row in each set of data.
The code should work even when one set of data is directly below the other as long as there is a blank row between them.
Below, in the code window, is the way the results should look, and it works fine when the second set of data starts in a completely different group of columns from the first set of data, as specified by the original spec. (Paste it into a sheet to see it formatted properly.)
In the attached file, Sheet1 gives the layout of data I want the code to work with.
Sheet2 shows the data in a format that works with the current macro, matchem_9()
The file also contains the current version of the code.
Try it first with set 1 as the first selection, and set 2 as the second selection. But, you should be able to use any set of data (1, 2, or 3) as the first selection, and any other as the second selection. If set 2 is selected first, then either 1 or 3 could be the second set, for example.
data set 1 word 9 any data 9 Mismatch data set 2 word 9 any data 9
data set 1 word 8 any data 8 data set 1 word 8 any data 8
data set 1 word 7 any data 7 data set 1 word 7 any data 7
data set 1 word 4 any data 4 data set 1 word 4 any data 4
data set 1 word 3 any data 3 data set 1 word 3 any data 3
data set 1 word 2 any data 2 data set 1 word 2 any data 2
data set 1 word 19 any data 19 data set 1 word 19 any data 19
data set 1 word 18 any data 18 data set 1 word 18 any data 18
data set 1 word 17 any data 17 data set 1 word 17 any data 17
data set 1 word 15 any data 15 Mismatch data set 1 word 6 any data 6
data set 1 word 14 any data 14 data set 1 word 14 any data 14
data set 1 word 13 any data 13 Mismatch data set 1 word 5 any data 5
data set 1 word 11 any data 11 data set 1 word 11 any data 11
data set 1 word 10 any data 10 data set 1 word 10 any data 10
data set 1 word 1 any data 1 Mismatch data set 1 word 16 any data 16
Mismatch data set 1 word 12 any data 12
MACRO-10-Sort-and-Match-by-Rows.xls
ASKER
Brad, that's working great. Could you do one more thing on this?
Instead of prompting the user if the sheet 'RSLT' already exists, can you tell the script to create 'RSLT1', and if 'RSLT1' exists, then create 'RSLT2', etc. This will be especially helpful when I need to run several comparisons of data at one time.
Here's how I've seen it done in another script:
Set myWB = Application.ActiveWorkbook
strNewSheet = "RSLT" & myWB.Sheets.Count + 1
etc.
Instead of prompting the user if the sheet 'RSLT' already exists, can you tell the script to create 'RSLT1', and if 'RSLT1' exists, then create 'RSLT2', etc. This will be especially helpful when I need to run several comparisons of data at one time.
Here's how I've seen it done in another script:
Set myWB = Application.ActiveWorkbook
strNewSheet = "RSLT" & myWB.Sheets.Count + 1
etc.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works great.
ASKER
You might be interested in my new question: Q_25351342
Excel: Multiple Words Based on Percentage
Excel: Multiple Words Based on Percentage
Jerry,
Thanks for the kind words and grade!
Brad
Thanks for the kind words and grade!
Brad
Excel VBA can find the last cell in a set by looking up from the bottom or by looking down from the top. The former is generally more reliable, but the latter is required by your latest specification.
Brad
Open in new window