abi_learn_vba
Board Regular
- Joined
- Nov 6, 2009
- Messages
- 215
Hi,
I have two issues.
First
I have below data (sample data) in sheet1 in my excel. I wanted to extact the rows which is <> 'Y' in column F3. But my my query does not return anything, but when i use = 'Y' it extract the two rows correctly.
Date
<TBODY>
</TBODY>
Code
Second:
With similar data when there are F3 values with both captial 'Y' and small 'y'.
<TBODY>
</TBODY>
With below code it would extract only two rows A and C, looks like the search value is case sensitive, is there a workaround for this. Like 'abi' and 'Abi' are same , 'y' and 'Y' are same.
This is a sample data and i am actually using huge rows of data.
Thanks & Regards
-Abi
I have two issues.
First
I have below data (sample data) in sheet1 in my excel. I wanted to extact the rows which is <> 'Y' in column F3. But my my query does not return anything, but when i use = 'Y' it extract the two rows correctly.
Date
F1 | F2 | F3 |
A | A | Y |
B | B | |
C | C | Y |
<TBODY>
</TBODY>
Code
Code:
Sub CHK()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim conStr As String
Dim sql As String
conStr = "provider=microsoft.jet.oledb.4.0;data source= " & ThisWorkbook.Path & "\" & ThisWorkbook.Name & ";extended properties=Excel 8.0;"
Set cn = New ADODB.Connection
cn.Open conStr
sql = "Select * from [Sheet1$] Where F3 <> 'Y'"
Set rs = New ADODB.Recordset
Set rs = cn.Execute(sql)
Range("H1").CopyFromRecordset rs
End Sub
Second:
With similar data when there are F3 values with both captial 'Y' and small 'y'.
F1 | F2 | F3 |
A | A | Y |
B | B | y |
C | C | Y |
<TBODY>
</TBODY>
With below code it would extract only two rows A and C, looks like the search value is case sensitive, is there a workaround for this. Like 'abi' and 'Abi' are same , 'y' and 'Y' are same.
Code:
Sub CHK()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim conStr As String
Dim sql As String
conStr = "provider=microsoft.jet.oledb.4.0;data source= " & ThisWorkbook.Path & "\" & ThisWorkbook.Name & ";extended properties=Excel 8.0;"
Set cn = New ADODB.Connection
cn.Open conStr
sql = "Select * from [Sheet1$] Where F3 = 'Y' "
Set rs = New ADODB.Recordset
Set rs = cn.Execute(sql)
Range("H1").CopyFromRecordset rs
End Sub
This is a sample data and i am actually using huge rows of data.
Thanks & Regards
-Abi