Capitalize all cells in columns "A", "B" and "C".

harzer

Board Regular
Joined
Dec 15, 2021
Messages
122
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
With this Macro, I want to capitalize all the cells of the following 3 columns: "A", "B" and "C".
Only when I run the Macro, only the cells in the first column are capitalized.
Where do you think the problem is?
Thank you for your suggestions

VBA Code:
Sub Mettre_En_Majuscule()

    Dim rng As Range
    Dim DLig As Long
    
    DLig = Sheets("Parents").Cells(Rows.Count, 1).End(xlUp).Row
    
    Set rng = Sheets("Parents").Range("A2:C" & DLig)
      
    With rng         
        tablo = .Value                              'matrice, plus rapide
            For i = 1 To UBound(tablo)
               tablo(i, 1) = UCase(tablo(i, 1))
            Next

        Application.EnableEvents = False
            .Value = tablo
        Application.EnableEvents = True
    End With

End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try adding an inner loop to pick up all 3 columns. Something like this

VBA Code:
For i = 1 To UBound(tablo)
        For c = 1 To 3
            tablo(i, c) = UCase(tablo(i, c))
        Next
Next
 
Upvote 0
Hello igold,
Thank you for your answer, the code satisfies me and gives the desired results.(y)
Just an additional question for this code that I need to use for another sheet, only the columns are not the same, hence the following question:
How can we modify this code so that it can capitalize the following columns: "A", "B", "C", "F", "I" and "J"?
Thank you in advance for your patience.
 
Upvote 0
I don't see your data, but if you want to keep using Arrays, and there is nothing in Columns "D", E", "G", "H" (Formulas) then you could do something like this which is loosely based on your previous code.

VBA Code:
Sub CapRows()

    Dim arr, cols
    Dim lRow As Long, i As Long, c As Long, col As Long
    
    lRow = Sheets("Parents").Cells(Rows.Count, 1).End(xlUp).Row
    cols = Array(1, 2, 3, 6, 9, 10) 'Numbers represent the column number to capitalize.
    arr = Sheets("Parents").Range("A2:J" & lRow)
    For i = 1 To UBound(arr)
        For c = 1 To UBound(cols) + 1
            col = cols(c - 1)
            arr(i, col) = UCase(arr(i, col))
        Next
    Next
    Sheets("Parents").Range("A2").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
      
End Sub
 
Upvote 0
Solution
Hello Igold,
Thank you for your new code, I can report that it works very well and gives me the right results. (y)
All the more, I don't have any formula in my data, Everything is fine.
A cordial handshake and with my thanks.
 
Upvote 0
Happy to help. Thanks for the feedback!
 
Upvote 0

Forum statistics

Threads
1,215,097
Messages
6,123,077
Members
449,094
Latest member
mystic19

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