Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to modify my code to not be case sensitive?

Posted on 2014-12-05
7
Medium Priority
?
87 Views
Last Modified: 2014-12-05
The below code searches for the string “BUILDING:", but it will only find it if it’s all in caps. How do I make it not be case sensitive?

strTmp = ""
strTmp = Filter(aLines, "BUILDING:")(0)
Range("X1") = Trim(Split(strTmp, ":")(1)

Open in new window

0
Comment
Question by:kbay808
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 26

Expert Comment

by:Nick67
ID: 40484075
Up at the top of the code module:
It's always good practice to have Option Explicit
Do you have an Option Compare set, too?

This will override it

strTmp = ""
strTmp = Filter(aLines, "BUILDING:",true,vbTextCompare)(0)
Range("X1") = Trim(Split(strTmp, ":")(1)
0
 

Author Comment

by:kbay808
ID: 40484081
I’m a novice so you lost me.  Here is my code.
Sub Description_Data()
On Error Resume Next
Range("W1:AK1").ClearContents
Range("W3:AK3").ClearContents
Range("W5:AK5").ClearContents
Range("W7:AK7").ClearContents
Range("W9:AK9").ClearContents
Range("W11:AK11").ClearContents
Range("W13:AK13").ClearContents

aLines = Split(Range("B11"), vbLf)

'Bldg

strTmp = ""
strTmp = Filter(aLines, "BLDG:")(0)
Range("W1") = Trim(Split(strTmp, ":")(1))

strTmp = ""
strTmp = Filter(aLines, "BUILDING:")(0)
Range("X1") = Trim(Split(strTmp, ":")(1))

strTmp = ""
strTmp = Filter(aLines, "BLDG")(0)
Range("Y1") = Trim(Split(strTmp, "G")(1))

strTmp = ""
strTmp = Filter(aLines, "BUILDING")(0)
Range("Z1") = Trim(Split(strTmp, "G")(1))

strTmp = ""
strTmp = Filter(aLines, "BLD")(0)
Range("AA1") = Trim(Split(strTmp, "D")(1))


End Sub

Open in new window

0
 
LVL 26

Expert Comment

by:Nick67
ID: 40484087
At the very top of the code put
Option Explicit

This requires you to define all your variables, and keeps the source of many subtle errors at bay
On Error Resume Next
You should use this ONLY as a very last ditch resort and certainly not while you actively developing.
This tells the code to keep going along merrily until it can't, ignoring all problems.
This can be VERY unhappy when you want a series of dependent things to occur.

You'll likely need
DIm aLines() as string
dim strTmp  as string
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Accepted Solution

by:
Nick67 earned 2000 total points
ID: 40484091
Try this

Option Explicit
Option Compare Text
Sub Description_Data()
Dim aLines() As String
Dim strTmp  As String
'On Error Resume Next
Range("W1:AK1").ClearContents
Range("W3:AK3").ClearContents
Range("W5:AK5").ClearContents
Range("W7:AK7").ClearContents
Range("W9:AK9").ClearContents
Range("W11:AK11").ClearContents
Range("W13:AK13").ClearContents

aLines = Split(Range("B11"), vbLf)

'Bldg

strTmp = ""
strTmp = Filter(aLines, "BLDG:")(0)
Range("W1") = Trim(Split(strTmp, ":")(1))

strTmp = ""
strTmp = Filter(aLines, "BUILDING:")(0)
Range("X1") = Trim(Split(strTmp, ":")(1))

strTmp = ""
strTmp = Filter(aLines, "BLDG")(0)
Range("Y1") = Trim(Split(strTmp, "G")(1))

strTmp = ""
strTmp = Filter(aLines, "BUILDING")(0)
Range("Z1") = Trim(Split(strTmp, "G")(1))

strTmp = ""
strTmp = Filter(aLines, "BLD")(0)
Range("AA1") = Trim(Split(strTmp, "D")(1))


End Sub

Open in new window

0
 

Author Closing Comment

by:kbay808
ID: 40484106
That did the trick.  Thank you very much for your help.
0
 
LVL 26

Expert Comment

by:Nick67
ID: 40484115
This would be better, as it is commented
Option Explicit
Option Compare Text
Sub Description_Data()
Dim aLines() As String
Dim strTmp  As String
'On Error Resume Next

'clear cells as required
Range("W1:AK1").ClearContents
Range("W3:AK3").ClearContents
Range("W5:AK5").ClearContents
Range("W7:AK7").ClearContents
Range("W9:AK9").ClearContents
Range("W11:AK11").ClearContents
Range("W13:AK13").ClearContents

'split B11 based on the linefeed character into an array
'usually though its vbCrLF
aLines = Split(Range("B11"), vbLf)

'Bldg

strTmp = ""
'look through the spilt for "BLDG:"
'Put the first instance in strTemp
strTmp = Filter(aLines, "BLDG:", True, vbTextCompare)(0)
'split the result on the colon, hammer the seond bit into the cell
Range("W1") = Trim(Split(strTmp, ":")(1))

'rinse and repeat
strTmp = ""
strTmp = Filter(aLines, "BUILDING:")(0)
Range("X1") = Trim(Split(strTmp, ":")(1))

strTmp = ""
strTmp = Filter(aLines, "BLDG")(0)
Range("Y1") = Trim(Split(strTmp, "G")(1))

strTmp = ""
strTmp = Filter(aLines, "BUILDING")(0)
Range("Z1") = Trim(Split(strTmp, "G")(1))

strTmp = ""
strTmp = Filter(aLines, "BLD")(0)
Range("AA1") = Trim(Split(strTmp, "D")(1))


End Sub

Open in new window

0
 
LVL 26

Expert Comment

by:Nick67
ID: 40484116
And I can't test this, but if it is bug-free, this would be best and most maintainable
Option Explicit
Option Compare Text
Sub Description_Data()

'clear cells as required
Range("W1:AK1").ClearContents
Range("W3:AK3").ClearContents
Range("W5:AK5").ClearContents
Range("W7:AK7").ClearContents
Range("W9:AK9").ClearContents
Range("W11:AK11").ClearContents
Range("W13:AK13").ClearContents

Call Pound(Range("B11"), Range("W1"), "BLDG:", ":")
Call Pound(Range("B11"), Range("X1"), "BUILDING:", ":")
Call Pound(Range("B11"), Range("Y1"), "BLDG", "G")
Call Pound(Range("B11"), Range("Z1"), "BUILDING", "G")
Call Pound(Range("B11"), Range("AA1"), "BLD", "D")


End Sub

Sub Pound(RInput As Range, ROutput As Range, TheString As String, SplitChar As String)
Dim aLines() As String
Dim strTmp  As String
'split RInput based on the linefeed character into an array
'usually though its vbCrLF
aLines = Split(RInput, vbLf)
'look through the spilt for TheString
'Put the first instance in strTemp
strTmp = Filter(aLines, TheString, True, vbTextCompare)(0)
'split the result on the final character, hammer the second bit into the cell
ROutput = Trim(Split(strTmp, SplitChar)(1))
End Sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question