+ Reply to Thread
Results 1 to 9 of 9

Font and Row Height with multi with or if statements

Hybrid View

  1. #1
    Registered User
    Join Date
    08-17-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    8

    Post Font and Row Height with multi with or if statements

    I am able to change the font size of my text based on location. However, I am unable to change the row size based on the same If Then criteria. I am unsure what I am doing wrong. any suggestions?!

    I keep getting the With object must be user-defined type, Object, or Variant error

     For Each s In Sheets
    
        s.Select
        Cells.Select
       
        With Selection
       
        End With
    
        For Each cll In ActiveSheet.Range("J101:J110")
            If Range("J101") = "Here!" Then
                With Range("A101:A113").FONT
                .Size = 12
                .Name = "Times New Roman"
                .Bold = False
                End With
                
            If Range("J101") = "Here!" Then
                With Range("A101:A113").Row
                    Cells.RowHeight = 15.75
            End With
    
     End If
        End If
       Next
    Next s
     
    End Sub
    #vba pro in training
    Last edited by sas2007; 08-21-2012 at 03:09 PM.

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Font and Row Height with multi with or if statements

    Hi sas2007, try this slightly modified version of your code
    Sub FormatCells()
        Dim s As Worksheet
        For Each s In Sheets
            For Each cll In s.Range("J101:J110")
                If s.Range("J101").Value = "Here!" Then
                    With s.Range("A101:A113").Cells.Font
                        .Size = 12
                        .Name = "Times New Roman"
                        .Bold = False
                    End With
                End If
                If s.Range("J101") = "Here!" Then
                    With s.Range("A101:A113").Rows
                        s.Cells.RowHeight = 15.75
                    End With
                End If
            Next cll
        Next s
    End Sub
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Registered User
    Join Date
    08-17-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Font and Row Height with multi with or if statements

    Thanks that really helps. the only thing is that it sets all my rows to 15.75. The rows above A101 are set to 19.

    I did add the value statement to the second ("J101") line


    Sub FormatCells()
        Dim s As Worksheet
        For Each s In Sheets
            For Each cll In s.Range("J101:J110")
                If s.Range("J101").Value = "Here!" Then
                    With s.Range("A101:A113").Cells.Font
                        .Size = 12
                        .Name = "Times New Roman"
                        .Bold = False
                    End With
                End If
                If s.Range("J101").Value = "Here!" Then
                    With s.Range("A101:A113").Rows
                        s.Cells.RowHeight = 15.75
                    End With
                End If
            Next cll
        Next s
    End Sub

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Font and Row Height with multi with or if statements

    Does that solve it?

  5. #5
    Registered User
    Join Date
    08-17-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Font and Row Height with multi with or if statements

    no all the row heights are setting to 15.75. I need only the cells that are set to font 12 to be set to row height 15.75. the other cells should be height=19

  6. #6
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Font and Row Height with multi with or if statements

    Try
    Sub FormatCells()
        Dim s As Worksheet
        For Each s In Sheets
                If s.Range("J101").Value = "Here!" Then
                    With s.Range("A101:A113").Cells.Font
                        .Size = 12
                        .Name = "Times New Roman"
                        .Bold = False
                    End With
                End If
                If s.Range("J101").Value = "Here!" Then
                    With s.Range("A101:A113").Cells.Rows
                        .RowHeight = 15.75
                    End With
                End If
        Next s
    End Sub

  7. #7
    Registered User
    Join Date
    08-17-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Font and Row Height with multi with or if statements

    oww well that worked well. Thanks!!

  8. #8
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Font and Row Height with multi with or if statements

    Quote Originally Posted by sas2007 View Post
    oww well that worked well. Thanks!!
    LoL, did it hurt?

  9. #9
    Registered User
    Join Date
    08-17-2012
    Location
    dc
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Font and Row Height with multi with or if statements

    lol not a bit!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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