Query worksheet using column range - excel

I'm trying to query an excel worksheet using ADODB. The problem is there are many columns with a similar name and I'm unable to select the correct column in my query. Is there a was to select the column by using its range? Something like
select [A:A],[AB:AB] from [Sheet1$]
The source worksheet kind of looks like this
A B C D E F G H I
1 08/19/2013 08/18/2013 08/17/2013
2 Col1 Col2 col3 col4 col5 col3 col4 col5 col3
3
When I try to import all the data I get all the data minus the column names, only col1 and col2 are fetched. Its the same when I do from [Sheet1$] and from [Sheet1$A2:K100]

If there are multiple columns with the same or similar names, Excel/ODBC will probably do some funky name-mangling to make sure they are different in the recordset. What I would do is get all the columns with "SELECT *" then examine the fields names in the result set - then you can go back and retrieve by name just the columns you want.

Related

How to filter a google sheet or excel table where only those rows are included where at least one of the cells is not blank

Consider this table:
Col1
Col2
Col3
Col4
1
s
2
3
s
What's the filter formula (or any other formula for that matter) so that it will only retain the rows if any of the cells from col2 to col4 is not empty?
So the output should be:
Col1
Col2
Col3
Col4
1
s
3
s
Google sheet sample here https://docs.google.com/spreadsheets/d/1ugIbzetQGb0IV32iE0aG49wEK1xSuFLHqDUnzoLnGnM/edit?usp=sharing
Thanks! Much appreciated.
One option for Google Sheets:
=FILTER(A1:D4,BYROW(B1:D4,LAMBDA(x,COUNTIF(x,"?*"))))
For ms365:
=FILTER(IF(A1:D4="","",A1:D4),BYROW(B1:D4,LAMBDA(x,SUM(--(x<>"")))))

How to write down the scenario outline example in cucumber, when you want to skip any column value and that column is mandatory for other test

col1
col2
col3
One
Three
Two
Three
for Col2, the value is not there to compare in "Than", so need to skip. But this column is having value to compare for other test.
Depends on your use case , but you can use null as a value for that column .

Fetch the unique rows from the tabs using sheets/excel formula

I need to build an index table dynamically from the sheetnames of the tabs (BLUE color).
The expected result is shown in YELLOW color.
The rows must be unique along with the sheetnames being displayed in the first column.
I tried in this sheet
Non Formula formula is here: =INDIRECT(CONCATENATE("{",TEXTJOIN(";",true,ARRAYFORMULA("'" &A6:A32 &"'!" & "A2:B")),"}"))
A formula solution is not possible for multiple sheets + indirect.
One option to solve this is to build the dynamic part of your formula with another formula.
Here's what I mean:
The dynamic part of the formula is constructed with this formula:
={"Dynamic part of the formula" ; JOIN(";"&char(10),FILTER("QUERY({"&A2:A&"!A2:C},""select '"&A2:A&"', Col1, Col2, Col3 where Col1 != '' label '"&A2:A&"' ''"")",A2:A<>"")) }
It assumes column A is released for sheet names only. It produces the result like this:
Dynamic part of the formula
QUERY({Sheet1!A2:C},"select 'Sheet1', Col1, Col2, Col3 where Col1 != '' label 'Sheet1' ''");
QUERY({Sheet2!A2:C},"select 'Sheet2', Col1, Col2, Col3 where Col1 != '' label 'Sheet2' ''");
QUERY({Sheet3!A2:C},"select 'Sheet3', Col1, Col2, Col3 where Col1 != '' label 'Sheet3' ''");
QUERY({Sheet4!A2:C},"select 'Sheet4', Col1, Col2, Col3 where Col1 != '' label 'Sheet4' ''")
The final formula uses this part. You'll need to do the next step manually or write a short script for this. Manual process:
Go to a cell with the generated part of the formula. Hit [F2] to enter it, select and copy all. Go to the final formula and replace this part:
={"Sheetname","sub_category","category_filter"; QUERY(UNIQUE({
QUERY({Sheet1!A2:C},"select 'Sheet1', Col1, Col2, Col3 where Col1 != '' label 'Sheet1' ''");
QUERY({Sheet2!A2:C},"select 'Sheet2', Col1, Col2, Col3 where Col1 != '' label 'Sheet2' ''");
QUERY({Sheet3!A2:C},"select 'Sheet3', Col1, Col2, Col3 where Col1 != '' label 'Sheet3' ''");
QUERY({Sheet4!A2:C},"select 'Sheet4', Col1, Col2, Col3 where Col1 != '' label 'Sheet4' ''")
}),"select Col1, Col2, Col3") }
I am sure there must be a more elegant formula to achieve the desired output.
However, this works just fine:
=query(UNIQUE({"Sheetname","sub_category","category_filter","duplicate";{ARRAYFORMULA("Sheet1"&T(SEQUENCE(COUNTA(Sheet1!A2:A))));ARRAYFORMULA("Sheet2"&T(SEQUENCE(COUNTA(Sheet2!A2:A))));
ARRAYFORMULA("Sheet3"&T(SEQUENCE(COUNTA(Sheet3!A2:A))))},{INDIRECT("Sheet1!A2:C"&COUNTA(Sheet1!A1:A));
INDIRECT("Sheet2!A2:C"&COUNTA(Sheet2!A1:A));INDIRECT("Sheet3!A2:C"&COUNTA(Sheet3!A1:A))}}),"Select Col1,Col2,Col3")

Is there a way to lookup the column header from the row hear and row value?

Looking for some help...
Is there a way to get the column header name based off the row header name and a value within the body, please note that there are duplicates.
For example from the below table based on RowH2 and table body X, the col1 and col3 column header names should be provided.
Col1 Col2 Col3
RowH1 X
RowH2 X X
RowH3 X
Thanks

VLOOKUP search issue

Am having some issue using the VLOOKUP function in excel. Am a little new to excel and puzzled as to how to solve this problem. I have two excel sheets.
Sheet 1 looks like:
Col1 Col2 Col3
HIC GSN ND11
H1C 00214 0212107
C4I 07287 0214380
L1A 07731 0214501
Sheet 2 looks like:
Col1 Col2 Col3 Col4 Col5 Col6 Col7
Condition HIC1 HIC1 HIC1 GSN GSN GSN
AMA B60 B61 B62 02934 02935
ALD H1A H1C 04821 03473
HEC W0A W0B
The VLOOKUP formula that am using is:
=VLOOKUP(B2,'Conditions.xlsx]Conditions'!$B$2:$BH$24,60,0)
Here B2 refers to Sheet 1, Column 1. Index Number 60 is a repeated Column 1 in Sheet 2. Is there a better way to lookup the COl1 and Col2 in Sheet one to extract the Conditions Columnin Sheet 2?
Any help would be great.
Read this: How to use INDEX MATCH instead of VLOOKUP
But what happens if you want to look from right to left? VLOOKUP simply can't do that. INDEX/MATCH can.

Resources