ADO Select Distinct Multiple Columns
Aug 5, 2009
I am using ADO to select data from a CSV file, column 1 has some duplicate Incident numbers, but the rest of the columns the data may be different but not interested in that so I cannot use SELECT DISTINCT incident, desciption as this applies to all columns
so I tried the following
StrSQL = "SELECT DT.IncidentNumber, ST.Description -
FROM (SELECT DISTINCT IncidentNumber FROM " & StrFile & " ) DT -
INNER JOIN " & StrFile & " ST ON DT.IncidentNumber = ST.IncidentNumber"
however it returns ALL rows, if I use just
SELECT DISTINCT IncidentNumber FROM " & StrFile
I get the rows I am interested in but not the extra data I require
View 9 Replies
ADVERTISEMENT
Sep 28, 2011
How to calculate a count of unique records across two columns (customer number and acct number) with out much luck. For example, a customer number may appear 3 times but be associated with 3 separate acct numbers.
I've found a lot of in-depth formulas online but I'm not sure if they're what I need. I think I need some sort of array formula but I'm a little stuck.
View 9 Replies
View Related
Aug 6, 2014
So far I created code that creates a Distinct Unique item's list for one column. It works as it should but I want to modify the code to create a Distinct Unique item's list for two columns that are related to another i.e. a person's name to their license #.
Here is the code below that works for one column only:
[Code] ......
View 9 Replies
View Related
Mar 19, 2007
From a base table, I need to create a new table listing only the unique combination of 2 columns and their individual sum. Example:
Base Table:
ITEM-----Loc-----QTY
Pen------School----5
Pencil----Office-----9
Binder---Office-----9
Pen------Office-----6
Pen------School---15
Binder---School---12
Pencil----Office----10
Binder---School----6
Pen------Office----11
I need to have a table resulting to the following:
Item-----Loc------Qty
Pen------School----20
Pencil----Office-----19
Binder---Office------9
Pen------Office-----17
Binder---School----18
View 9 Replies
View Related
May 30, 2014
I have two lists in different columns, which are defined ranges. I want to extract them to a unique list with an array formula and at the same time sort albafetically, without duplicates, like this:
List1
List2
Final List
Audi
Ford
[Code] ....
So far, I have this formula which is working in what concerns removing duplicates and exctract a unique list. But it is not ordering alfabeticaly.
{=IFERROR(IFERROR(INDEX(List1, MATCH(0, COUNTIF($D$1:D1, List1), 0)), INDEX(List2, MATCH(0, COUNTIF($D$1:D1, List2), 0))), "")}
View 2 Replies
View Related
Mar 4, 2009
I have VBA code below. Currently the code allows me in column "N" to choose more than one item in a dropdown menu. I am trying to find a way to make column K and M do the same thing. I have tried a number of ways but to no avail.
View 2 Replies
View Related
Nov 1, 2012
To select multiple columns I can use Union but can I use something that will cicle through the values from an array?
Example (how do I see this)
VB :
columnsToDelete= array("UM","Post","Pre")
For i=0 To UBound(columnsToDelete)
Set columnsFound=Range("1:1").find(what:=columnsToDelete(i), lookin:=xlvalues,lookat:=xlwhole, matchcase:=True)
columnsFound.select
Selection delete
Next i
View 2 Replies
View Related
Sep 15, 2008
I am using VBA to change the format of columns. The code work with 1 column, but In need to change the format of mulitiple columns. E.g Cols 11 to 22. I tried the code below but it does not work!
View 3 Replies
View Related
Nov 25, 2011
I'm trying to write some code to select cells in a number of columns on a variable row. I have the following code to define the rownumbers for Cash and Pal:
Columns("G:G").Select
Selection.Find(What:="Total Cash", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
[Code]....
Then I can use the following code to select a cell in a single column:
Range("P" & Cash & ":P" & Pal).Select
but I need to select cells in columns P, R, T, V, X, etc.....
If I was doing this for a fixed rownumber I would use:
Range("P22:P23,R22:R23,T22:T23,V22:V23,X22:X23").Select
but because my rownumber is variable I tried to use:
Range("P" & Cash & ":P" & Pal, "R" & Cash & ":R" & Pal, "T" & Cash & ":T" & Pal, "V" & Cash & ":V" & Pal, "X" & Cash & ":X" & Pal).Select
but this doesn't work giving the Compile error: Wrong number of arguments or invalid property assignments
View 4 Replies
View Related
Feb 20, 2014
I have a spreadsheet with a heap of raw data in it. I need to perform a search based on a customer name, then return certain columns from the raw data IF the customer name is matched in one column, AND a special flag name is matched in a second column. The customer name is always a single entry for the purpose of the query, however the special flag must be checked against a possible list of values in a table. I know this is hard to explain, and I can't add attachments to my posts, so I have created a sample document and placed in in dropbox:
[URL] ........
View 9 Replies
View Related
Sep 25, 2013
I would like a macro that select all cells based on multiple criteria. It's a big sheet, but I've made it smaller in the following example.
In row 1, there are 2 headers, in B1 (electricity) and C1 (gas) In column A, there are 3 houses, in A2, A6 and A10. The blocks of cells in between (e.g. B2:B5) have 2 headers, 'period' in B2, and 'account number' in B4. B3 and B5 have a list of options in them.
I want to select cells that meet certain criteria. Either electricity or gas, and either period or account number. So, if in cell D1 I choose electricity and in D2 period, I would like to select B3, B7 and B11. If I choose gas and account number, I wish to select C5, C9 and C13.
View 1 Replies
View Related
Jul 30, 2014
I have a set of cells and i want it to return all of the distinct or unique values within that matrix. for example, lets say this table charts how many sales an employee makes in a week.
sun mon tues weds thurs fri sat
john doe 1 0 3 2 3 0 0
jane doe 0 8 0 1 0 7 0
james doe 3 3 2 3 2 1 1
the desired output would be: 0,1,2,3,7,8
I don't want to be copying all of the cells or doing a lot of manipulation - i know i can copy, sort, and get unique values that way - i want a formula where as i plug in values, this field is updated to include all of the distinct or unique values.
View 2 Replies
View Related
Jan 21, 2014
I have a spreadsheet which contains (see illustration below):
1. a column called LEAD ID which contains a unique id
2. a column called WON which signifies if the deal was won/not won (1 = WON, blank = Not Won)
I can have multiples of the same value in the Won and Unique Id field (see illustration below)
I would like to create a formula field which returns the summary of the No. of Deals WON
I need to tie the formula back to the Lead ID and whether or not the WON field contains 1 or not.
I've tried this formula but it won't work
(Lead ID is in Column A, WON is in column B)
=IFERROR(SUM(1/COUNTIF((A:A,A:A) AND(B2=1)),"0")
LEAD ID WON No. Won (Formula field)
abc112 0
abc222 1 .25
abc222 1 .25
abc222 1 .25
abc222 1 .25
abc333 1 1
abc444 0
View 9 Replies
View Related
Sep 18, 2012
I'm a huge fan of the DistinctValues function published by C Pearson here: Distinct Values Function
Now I have the problem that I need to get all the distinct values from a 2-dimensional range.
View 1 Replies
View Related
Apr 3, 2013
I have a workbook with multiple sheets. On each sheet is different sets of sales person data. Each set consists of a sales order number, and the type of product that was sold.
I need a count of all the distinct product types that each sales person sold.
I need the solution in VBA, as i need to run the macro through all the worksheets. The size of the range for each sales person differs.
I have got all the VBA done, except for the part where i specify the FORMULAR1C1 for the specific cell, to do the distinct count.
View 1 Replies
View Related
Apr 18, 2013
I am trying to count multiple occurences.
Instrument Name
Times Traded
AEON CO LTD
6
ASICS CORP
3
ELECTRIC POWER DEVELOPMENT C
10
In column C (Times Traded) I have used a simple countif formula: =COUNTIF($B$2:$B$8068, C2)
Now I have to check for how many times this instrument was bought or sold. This is in column A .... How will I count the Buy values ... cause this formula I devised doesnt work =COUNTIF($B$2:$B$8068, and(C2, A2:A8068="Buy")
View 4 Replies
View Related
Jul 22, 2014
I have several sheets in one workbook. For ease, the sheets are labeled Customer1, Customer2, Customer3 etc. Within these sheets are 5 columns of data, with unique headings that are consistent for all Sheets.
In Column A of each Customer sheet, is the Product ID number. I would like a distinct list of all Product ID numbers in the workbook, across all Sheets. (The amount of data in each sheet may increase or decrease)
View 7 Replies
View Related
Dec 23, 2006
I have this formula that works perfectly in Excel. It counts the unique TEXT values in a column. But it does not work in the VBA editor. Count = SUMPRODUCT((C6:C39<>"")/COUNTIF(C6:C39,C6:C39&""))
View 2 Replies
View Related
Aug 5, 2014
I'm working with a set of text values. The sets of text can be either 2 or 3 chars long (in this example 2), and are separated with a pipe. The end char for each set of chars in fixed. In this case a Z.
I'm looking for a formula which counts the unique / distict number of sets of chars. I have been trying to use COUNTIF with a wildcard (?Z), but unfortunately I haven't been able to find the correct formula yet.
For example.
|AZ|AZ|AZ|BZ|AZ|AZ|BZ|AZ|BZ|AZ| -> 2 (AZ, BZ)
|AZ|AZ|AZ|BZ|CZ|AZ|CZ|AZ|BZ|AZ| -> 3 (AZ, BZ, CZ)
|CZ|BZ|AZ|BZ|CZ|AZ|EZ|AZ|FZ|AZ| -> 5 (AZ, BZ, CZ, EZ, FZ)
|BZ|BZ|AZ|BZ|CZ|AZ|EZ|AZ|GZ|AZ| -> 5 (AZ, BZ, CZ, EZ, GZ)
View 9 Replies
View Related
Aug 21, 2014
I am attempting to create a datasheet to track the actual time an agent takes a break or lunch. Here is an example of the data that I am using.
name Date Lunch Sch Brk1 Sch Brk 2 Actual Time
BrandonHolt8/19/201411:10 8:30 1:20 8:24:20 Break
BrandonHolt8/19/201411:10 8:30 1:20 11:42:34 Break
BrandonHolt8/19/201411:10 8:30 1:20 12:57:46 Lunch
Because I have two break times, possibility of more depending on the agent, how do i create a formula that will look at this data, take the schedule time for say break one and only apply that against the time that is more in line with the closest actual time?
View 1 Replies
View Related
Feb 24, 2014
I have an excel which is containing records of users who have given an online test.Many users have given the test multiple times. I need to extract the records of every individual with the highest score. example it could be individual A, B and C have given the test 3 times with different scores achieved. I need the records of A, B and C in which their score was maximum.
View 7 Replies
View Related
Feb 8, 2010
This question about conditional formatting appears to be easy. Lets say I have a column like the following, like I posted somewhere else: (not very relevant for this)
BGW
3UG
WWU
1BR
UUBRG
WUBRG
7UUGGRRR
How do I have all characters in this column be coloured accordingly to:
W = WHITE
U = BLUE
B = BLACK
R = RED
G = GREEN
So that 7UUGGRRR would automatically switch to:
7UUGGRRR
What I already tried:
- I applied conditional formatting to the column (actually, the cells interval, [C2..C8]) creating the rule: 'format only cells that contain -> specific text' -> then I added "U" as the text and told it to colour blue. As I predicted, this didn't work; the entire cell containing a single "U" will get blue, which is unwanted.
View 9 Replies
View Related
Sep 12, 2012
I have two tables on two different worksheets. I would like to automatically populate a distinct list into column A in table 2 from the data in column A in table 1.
Table 2 must auto populate from table 2 every time a new row is added into table 1 - without any extra user interaction e.g. pressing a button etc. No offense intended to my better half but if she has to do anything more than enter a new row in table 1 she'll likely manage to screw it up after a week
I kind of managed to get it working using the below formula but both sets of data must be in tables so I can't copy the formula down the column without creating redundant table rows.
=INDEX(Classes!$A$2:$A$999, MATCH(0, COUNTIF($A$1:A1, Classes!$A$2:$A$9), 0))
Example
Sheet 1 = "Classes"
Column A = "Student Names"
John
Mike
Paul
Andrew
Paul
Paul
Mike
Sheet 2 = "Total Due"
Column A = "Student Names"
Paul
Mike
View 3 Replies
View Related
Jul 16, 2013
I am trying to create an alphabetised unique list for a report from an Excel master file and have searched the internet for solutions which all only seem to half work for me. I've copied a couple of array formulae below to try what I'm after and what the results are. 'RefSource' is the name I've given to the column of data I'm trying to sort.
{=INDEX(RefSource, MATCH(0, COUNTIF($A$2:A2, RefSource),0))}
This one works when I copy the formula down and gives me the unique list but doesn't sort the it into alphabetical order.
{=INDEX(RefSource, MATCH(MIN(IF(COUNTIF($P$1:P1, List)=0, 1, MAX((COUNTIF(RefSource, "
View 1 Replies
View Related
Apr 7, 2008
I have a workbook with two worksheets:
Input
Entitlment
On workbook called "Input" range A2 downwards are a series of staff names, non unique
When I select the worksheet called "Entitlement" I would like on this sheet range A2 downwards to list staff names in alphabetical order but only unique occurances of a persons name.
eg if on sheet "Input" cell A2="darrenS", A3="darrenS", A4="EdwardG", A5="EdwardH"
upon selecting "Entitlement" sheet
A2 would show "darrenS"
A3 would show "EdwardG"
A4 would show "EdwardH"
I user will then have to enter a number relating to number of accounts in ColumnB
should a name already have an existing number next to it then when the worksheet "Entitlment" is selected again the number will reamin associated to the name. When sorting occurs !
View 9 Replies
View Related
Feb 9, 2009
I have a problem getting an adequate formula for the following.
"Sheet 1"
Column A.............Column B
Employee Code.....Distinct Count
ZZADW...............Formula Result
ZZALM................Formula Result
ZZALS................Formula Result
ZZANG................Formula Result
"Sheet 2"
Column A............Column B
Employee Code.....Account Number
ZZADW...............1SSS
ZZADW...............1STT
ZZALM................5GHL''''''''
View 9 Replies
View Related
Jan 2, 2010
I'm looking for a SUBTOTAl IF function (if there's any) that would sum all the distinct values in a column for a given criteria based on another column. My data is listed below:
Column A Column B
(Quarter) (Revenue)
Q1 2008 $10
Q1 2008 $10
Q1 2008 $20
Q2 2008 $15
Q3 2008 $25
Q3 2008 $25
I'm looking for a formula to sum the DISTINCT Revenue values for Q1 2008, Q2 2008, and Q3 2008 based on the autofiltered list. The formula result should change dynamically based on the autofilter selection.
View 9 Replies
View Related
Apr 1, 2014
I want to select a number of columns. I know the column indexes.
I want to use something like (Doesn't work):
[Code] ......
Instead of (Works):
[Code] ....
Rows can be selected according to:
[Code] ....
I have written this code that works. But there must be an easier way:
[Code] ....
View 4 Replies
View Related
Jun 26, 2009
I'm in the midst of preparing a Year-To-Date (YTD) simple financial report in MS Excel.
Firstly:
I allow user to enter a number in cell A2.
Secondly:
Cells from A4 - L4 are linked from Sheet1. Cell M4 will give sum of A4:L4. Users are not allowed to change data in cells from A4 - L4. Users are only required to enter a number between 1 to 12 in cell A2. Upon update cell A2, the VBA shall sum the number of columns as entered in cell A2.
For example, if user enter 3 in cell A2 then cell M4 must give sum of A4:C4. If user enter 8 in cell A2 then cell M4 must give sum of A4:H4.
View 9 Replies
View Related
Sep 27, 2007
an equivalent to the code
rows("8:10").select
for columns. I don't want to use the A, B notation but rather, column numbers.
View 6 Replies
View Related