+ Reply to Thread
Results 1 to 7 of 7

VBA code to adjust row height for searched cells

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    New Plymouth Taranaki
    MS-Off Ver
    2013
    Posts
    29

    VBA code to adjust row height for searched cells

    Hi,
    I have this code to find specific text entries in a ledger. It then bolds the cell. While I have located this cell, how can I then make the row active to adjust the row height?
    thanks

    Sub Boldtotalcostofsales()
    
    'bolds total cost of sales title
    
    Dim c As Range, firstaddress As String, ws As Worksheet, FindMe As String
    
    FindMe = "Total Cost Of Sales"
    
    'the value to find
    
    For Each ws In ThisWorkbook.Worksheets
    
    'loop through each worksheet
    
    With ws.UsedRange
    
        Set c = .Find(FindMe, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
    
        If Not c Is Nothing Then
    
            firstaddress = c.Address
    
            Do
    
                c.Font.Bold = True
                
    
                'if found, make it bold
    
                Set c = .FindNext(c)
                
    
            Loop While Not c Is Nothing And c.Address <> firstaddress
    
        End If
    
    End With
    
    Next ws
        
    End Sub
    [

  2. #2
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA code to adjust row height for searched cells

    Try this

    Sub Boldtotalcostofsales()
    
        'bolds total cost of sales title
        Dim c As Range, firstaddress As String, ws As Worksheet, FindMe As String
        
        'the value to find
        FindMe = "Total Cost Of Sales"
        
        For Each ws In ThisWorkbook.Worksheets
            'loop through each worksheet
            With ws.UsedRange
                Set c = .Find(FindMe, LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=True)
    
                If Not c Is Nothing Then
                    firstaddress = c.Address
    
                    Do
                        'if found, make it bold and adjust height
                        c.Font.Bold = True
                        c.Rows.AutoFit
    
                        Set c = .FindNext(c)
                    Loop While Not c Is Nothing And c.Address <> firstaddress
                End If
            End With
        Next ws
    
    End Sub
    Thanks

  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    New Plymouth Taranaki
    MS-Off Ver
    2013
    Posts
    29

    Re: VBA code to adjust row height for searched cells

    Thank you Fredlo2010.
    I set the row height to the desired height instead of the auto fit and worked.

    Much appreciated.

  4. #4
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA code to adjust row height for searched cells

    Hi,

    Change this

    c.Rows.AutoFit
    to

    c.Rows.Height = 24
    Thanks

  5. #5
    Registered User
    Join Date
    06-26-2014
    Location
    New Plymouth Taranaki
    MS-Off Ver
    2013
    Posts
    29

    Re: VBA code to adjust row height for searched cells

    Yes, did that thanks.
    Just noticed another problem,
    I want the rest of the row to be centre justified, I thought I had solved this with
            Do
                c.Font.Bold = True
                c.Rows.RowHeight = 22.25
                c.Rows.VerticalAlignment = xlCenter
    
                Set c = .FindNext(c)
    but it doesn't seem to work.

  6. #6
    Valued Forum Contributor fredlo2010's Avatar
    Join Date
    07-04-2012
    Location
    Miami, United States
    MS-Off Ver
    Excel 365
    Posts
    762

    Re: VBA code to adjust row height for searched cells

    Try,

    c.EntireRow.VerticalAlignment = xlCenter

  7. #7
    Registered User
    Join Date
    06-26-2014
    Location
    New Plymouth Taranaki
    MS-Off Ver
    2013
    Posts
    29

    Re: VBA code to adjust row height for searched cells

    Ohh I like you!

    Yes. Great stuff.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Auto adjust row height in formula-cells
    By Ztv in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-17-2014, 07:19 AM
  2. Auto adjust Row Height of Merged and Unmerged cells
    By domino21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-03-2012, 09:11 PM
  3. Adjust row height for merged cells
    By mozaic in forum Excel General
    Replies: 6
    Last Post: 11-08-2011, 03:18 AM
  4. adjust lastrow In Col to a height of 7.5
    By erock24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-20-2008, 01:25 PM
  5. auto adjust row height
    By maacmaac in forum Excel General
    Replies: 2
    Last Post: 03-14-2007, 05:54 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1