Grouping case insensitive

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
The code below is used to extract data from a csv file.

Rich (BB code):
Option Explicit
Option Text Compare

Sub GetData()    

Dim cn As ADODB.Connection Dim rs As ADODB.Recordset Dim strcon As String Dim strSQL As String
Set cn = New ADODB.Connection strcon = "Provider = Microsoft.ACE.OLEDB.12.0;" & _ "Data Source=C:\MyData\;" & _ "Extended Properties=""text;" & _ "HDR=Yes;" & _ "FMT=Delimited""" cn.Open ConnectionString:=strcon Set rs = New ADODB.Recordset rs.CursorLocation = adUseServer Dim File As String Dim rng As Range File = "[MyData.csv]" strSQL = "SELECT [Location], SUM([Price]) AS [Sum Price]" & _ "FROM " & File & _ "GROUP BY [Location]" Set rng = Sheet1.Cells(2, 1) rs.Open Source:=strSQL, _ ActiveConnection:=cn, _ CursorType:=adOpenForwardOnly, _ LockType:=adLockReadOnly, _ Options:=adCmdText rng.CopyFromRecordset Data:=rs End Sub

The problem is even with Option Text Compare, it STILL is case sensitive, ie if I have two locations, London and LONDON in my data, the Group By clause treats these two locations as different and thus does not group them.

What can be done?

Thanks
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
my Access doesnt make the distinction of case, it treats both the same.
but
make another field in the query to Ucase the group:

GroupCity: Ucase([city])
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top