Tim Hanson
Member
I have a proper case macro that I need to run on multiple columns.
I am tiring to add an array of header names and so run from this list.
When I run the compound macro nothing happens, no errors but no execution of the propercase macro either
Thanks
I am tiring to add an array of header names and so run from this list.
When I run the compound macro nothing happens, no errors but no execution of the propercase macro either
Thanks
Code:
Option Explicit
Sub ProperCaseByList()
Dim strSearch As String
Dim aCell As Range
Dim LastRow As Long
Dim myRange As Range
Dim tmpString As String, Convert_This As String
Dim MyString As Variant
Dim I As Long
Dim X As String
'Application.ScreenUpdating = False
'****************************************************************
strSearch = "user first name, user last name, first name, last name"
'****************************************************************
With Sheets(1)
Set aCell = .Rows(1).Find(What:=strSearch, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not aCell Is Nothing Then
LastRow = .Cells(.Rows.Count, aCell.Column).End(xlUp).Row
With myRange = .Range(aCell, .Cells(LastRow, aCell.Column))
'PROPERCASE
'The original range
'Set myRange = .Range("D2", .Range("D" & .Rows.Count).End(xlUp))
For Each aCell In myRange
tmpString = vbNullString
If InStr(1, aCell.Formula, ",") Then
MyString = Split(aCell.Formula, ",")
Convert_This = MyString(0)
For I = 1 To UBound(MyString)
tmpString = tmpString & MyString(I) & ","
Next I
tmpString = Left(tmpString, Len(tmpString) - 1)
Else
Convert_This = aCell.Value
End If
aCell.Value = Application.WorksheetFunction.Proper(Convert_This) & IIf(tmpString = vbNullString, tmpString, "," & tmpString)
Next aCell
End With
End If
End With
'Application.ScreenUpdating = True
End Sub