Increasing row height if condition is met using VBA.

hubble101

New Member
Joined
Oct 22, 2018
Messages
5
Hey team, my VBA knowledge is extremely little, so hoping I could get some help here!

I currently have a worksheet that automatically generates "Total" in a cell when a certain condition is met through an IF function.

I now want to increase the row height, font and font size in the row that the word "Total" appears.

In the worksheet, the word "Total" can be anywhere from C9:C500, I would like the row height to be 30, the font to be Times New Roman, and the font size to be 20.

If there is any further information you require, please let me know!
thanks :)
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Like this?

Code:
Sub Macro1()


Dim rownum As Long


rownum = 9


On Error GoTo nextrow
Do Until rownum = 501
    If Cells(rownum, 3).Value = "Total" Then
        With Rows(rownum)
        .RowHeight = 22.5
        .Font.Name = "Times New Roman"
        .Font.Size = 20
        End With
    End If
nextrow:
rownum = rownum + 1
Loop


End Sub
 
Last edited:
Upvote 0
Like this?

Code:
Sub Macro1()


Dim rownum As Long


rownum = 9


On Error GoTo nextrow
Do Until rownum = 501
    If Cells(rownum, 3).Value = "Total" Then
        With Rows(rownum)
        .RowHeight = 22.5
        .Font.Name = "Times New Roman"
        .Font.Size = 20
        End With
    End If
nextrow:
rownum = rownum + 1
Loop


End Sub



Thank you so much for getting back to me so quickly, this runs perfectly!

Is there a way to have this automatically run everytime an edit is made, rather than having to run manually?
 
Upvote 0
Thank you so much for getting back to me so quickly, this runs perfectly!

Is there a way to have this automatically run everytime an edit is made, rather than having to run manually?

And also to set the row height to the rows this criterion isn't met to 15 whenever it is run?
 
Upvote 0
This may be quicker.....but why rerun the code every time a cell changes ??

Code:
Sub MM1()
Dim FR As Long
With Sheets("sheet1")
    Set FindRow = .Range("C:C").Find(What:="Total", LookIn:=xlValues)
End With
FR = FindRow.Row
    With Rows(FR)
            .RowHeight = 30
            .Font.Name = "Times New Roman"
            .Font.Size = 20
    End With
End Sub
 
Last edited:
Upvote 0
That means you will need to "Unformat" each row each time to reformat the cells to the required format....
Why not setup the page with 15 piont size as the default ???
 
Upvote 0
That means you will need to "Unformat" each row each time to reformat the cells to the required format....
Why not setup the page with 15 piont size as the default ???

Hi Michael, thank you for the suggestion! As mentioned, excel is definitely not my strong suit :)

Perhaps I could instead run it everytime the sheet is selected? This will be used by other employees who have even less excel knowledge than me, they are basically inputting data into one sheet, and having it format on another. I feel that having it run the code everytime the sheet is selected would be ideal for this, if it is at all possible :)
 
Upvote 0
OK, in that case you need to define for us what are the default formats, so that when the sheet is activated it returns everything to "normal" first, then runs the find code !!
 
Upvote 0
Hi Michael, would you hate me if I said I didn't know how to check this? Haha

As I have been attempting to format this sheet in an aesthetic way, there are many different column heights.

If I remove everything confidential and send the sheet through, would that be a help?

Thanks in advance! :)
 
Upvote 0
Sorry can't accept mailed workbooks !!
But if the cells change, won't the total still be the Total wherever it is in the column. ????
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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