Extracting data from another workbook; Sheet name might change case.

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
393
Office Version
  1. 365
Platform
  1. Windows
Gurus,
below code sometime cannot extract data from the workbook because of sheet name letter case change eg from flt to FLT. Is there a way for me to set up different conditions so that I can at least make the extracting process more automatic?


VBA Code:
ActiveWorkbook.queries.Add Name:=queryname, Formula:= _
        "let Source = Excel.Workbook(File.Contents(""" & getpath_vol & """), null, true), FLT_Sheet = Source{[Item=""FLT"",Kind=""Sheet""]}[Data]" & "in" & " FLT_Sheet"
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Hi there. You could loop through the sheets to get the correct case of the sheet name.

VBA Code:
Private Function GetSheetNameThatMatchesStringCaseInsensitive(ByVal str As String) As String
    Dim sheet As Variant
    For Each sheet In ThisWorkbook.Worksheets
        If UCase(sheet.Name) = UCase(str) Then
            GetSheetNameThatMatchesStringCaseInsensitive = sheet.Name
            Exit Function
        End If
    Next sheet
End Function
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,575
Members
449,039
Latest member
Arbind kumar

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