jmoney1440p
New Member
- Joined
- Dec 21, 2020
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi there, I am looking for assistance in writing VBA code to do the following.
1) Loop through the first row of every column
2) I want to identify every column where the first row contains the string "rate" in any variation.
3) Select all columns w/ "rate" in the first row and percentage their contents with decimal moved 2 places.
I work with large amounts of data and currently have to manually "percentage-ize" the columns that contain rates in them. I would like a macro that reads the first row (column header) and checks if the word "rate" is present, if true, percentage-ize the entire column.
I've tried something like this below, but my "rng" is returning an error, and I don't know too much about VBA.
Sub RateCheck()
Dim rng As Range
Dim cl As Object
Dim strMatch As String
strMatch = "rate"
Set rng = ActiveWorkbook.UsedRange.Rows(1).Cells
For Each cl In rng
If InStr(cl, strMatch) > 0 Then
cl.Columns.Select
Selection.Style = "Percent"
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
End If
Next
End Sub
1) Loop through the first row of every column
2) I want to identify every column where the first row contains the string "rate" in any variation.
3) Select all columns w/ "rate" in the first row and percentage their contents with decimal moved 2 places.
I work with large amounts of data and currently have to manually "percentage-ize" the columns that contain rates in them. I would like a macro that reads the first row (column header) and checks if the word "rate" is present, if true, percentage-ize the entire column.
I've tried something like this below, but my "rng" is returning an error, and I don't know too much about VBA.
Sub RateCheck()
Dim rng As Range
Dim cl As Object
Dim strMatch As String
strMatch = "rate"
Set rng = ActiveWorkbook.UsedRange.Rows(1).Cells
For Each cl In rng
If InStr(cl, strMatch) > 0 Then
cl.Columns.Select
Selection.Style = "Percent"
Selection.NumberFormat = "0.0%"
Selection.NumberFormat = "0.00%"
End If
Next
End Sub