Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

Splitting a string and capitalizing letters based on cases

$
0
0

I have some column names with starting coding convention that I would like to transform, see example:

   Original        Target     
 ------------- -------------- 
  partID        Part ID       
  completedBy   Completed By 

I have a function in VBA that splits the original string by capital letters:

Function SplitCaps(strIn As String) As String
Dim objRegex As Object
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
    .Global = True
    .Pattern = "([a-z])([A-Z])"
    SplitCaps = .Replace(strIn, "$1 $2")
End With
End Function

I wrap this function within PROPER, for example, PROPER(SplitCaps(A3)) produces the desired result for the third row but leaves the "D" in ID uncapitalized.

   Original        Actual    
 ------------- -------------- 
  partID        Part Id       
  completedBy   Completed By 

Can anyone think of a solution to add cases to this function?


Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>