+ Reply to Thread
Results 1 to 3 of 3

Hiding rows with italic words

Hybrid View

  1. #1
    Registered User
    Join Date
    02-23-2010
    Location
    Oxfordshire, UK
    MS-Off Ver
    Excel 2003
    Posts
    1

    Hiding rows with italic words

    Hi

    Firstly apologies as i am very new to all this, have no experience with computer programming, and am stumbling around vba somewhat! I have spent days googling but have got nowhere with this.

    I have a sheet which i use to record species of freshwater invertebrates. These are recorded to either species level, or a higher level. The species names are in italics, but the other names are not. The data is then uploaded to a database.

    I wanted to create a macro so that i can press a button to hide, and another button to reveal, the species names, leaving the other names intact.The list runs to hundreds of species but far fewer at the higher level, and navigation for inputting is much easier without seeing the species names. The species names are all in column A. An example is below with them revealed:

    Ephemerellidae
    Serratella ignita
    Potamanthidae
    Potamanthus luteus
    Taeniopterygidae
    Brachyptera risi
    Taeniopteryx nebulosa


    and with the hide macro run:

    Ephemerellidae
    Potamanthidae
    Taeniopterygidae

    I recorded a macro to find out how to select cells with italic font:

    Columns("A:A").Select
        With Application.FindFormat.Font
            .FontStyle = "Italic"
            .Subscript = False
            
        End With

    I thought putting 'Selection.EntireRow.Hide' might then hide the rows but it doesn't work.

    Can anyone see what i am doing wrong? I think it is probably quite a simple thing, but as i said, i don't have a clue what i am doing!

    Cheers

    Tim
    Last edited by NBVC; 02-23-2010 at 03:02 PM.

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Hiding rows with italic words

    You could try:

    Sub Hide()
    
    Dim lngLastRow As Long, rngFontRange As Range
    
    lngLastRow = Cells(Rows.Count, 1).End(xlUp).Row
    
    For Each rngFontRange In Range("A1:A" & lngLastRow)
    
    If rngFontRange.Font.Italic Then
    
    rngFontRange.EntireRow.Hidden = True
    
    End If
    
    Next rngFontRange
    
    End Sub
    
    Sub Unhide()
    
    Rows.Hidden = False
    
    End Sub
    It might be possible with findformat, would need to test it out in 2007 though.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,861

    Lightbulb Re: Hiding rows with italic words

    I have attached a solution that takes a slightly different approach and probably will be more flexible for you. Let me know what you think.

    This approach has two parts. First, it adds a column that says whether it's a species, based on font. Then you can use AutoFilter to select the ones that are species, based on that column.

    Second, the value in the new column is determined by a simple user-defined function, which you can find in Module1.
    Attached Files Attached Files
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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