Consulting

Results 1 to 3 of 3

Thread: Search, find, hide columns - VBA

  1. #1

    Search, find, hide columns - VBA

    Hello,

    I have an excel file: columns A:G contain not very important data, but H:XXX contains the translated data. In each column from H to the end I have different language and country (e.g. de_DE or el_GR). I would like to write a code that is looking for in header a local that I want to have unhide and the rest (from H to XXX) will be hide. The data A:G stay untouched.

    I wrote something but it does not work:

    Sub Hajd()


    Dim locale As String
    locale = InputBox("Which column should not be hidden?", "Hide columns")
        
        For i = 8 To 1000
            
         If Cells(1, i).Value = locale Then
            Cells(1, i).Column.Visible = True
        Else
            Cells(1, i).Column.Visible = False
        End If
    Next
    
    
       End Sub
    Could you please help me?

    Many thanks

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,874
    There is no .visible property of a range, only .hidden.
    Dim locale As String
    locale = InputBox("Which column should not be hidden?", "Hide columns")
    For i = 8 To 1000
      If Cells(1, i).Value = locale Then
        Columns(i).Hidden = False
      Else
        Columns(i).Hidden = True
      End If
    Next
    but faster (and case insensitive (so you don't have to get the header capitals correct)):
    Dim locale As String
    locale = InputBox("Which column should not be hidden?", "Hide columns")
    locale = UCase(locale)
    Columns("H:ALL").Hidden = True
    For i = 8 To 1000
      If UCase(Cells(1, i).Value) = locale Then Columns(i).Hidden = False
    Next
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    Thank you so much! That's very kind!

Posting Permissions

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