Consulting

Results 1 to 4 of 4

Thread: How to ignore hidden columns

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location

    How to ignore hidden columns

    Hello people,

    I have made following code,
    this is a very easy loop that loops all used cells in active sheet.

    Sub test()
    
    
    For x = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
     ' put some code here.
    Next x
    
    
    End Sub
    How can I make the loop ignore hidden columns?

    Thank you in advance

  2. #2
    VBAX Tutor PAB's Avatar
    Joined
    Nov 2011
    Location
    London (UK)
    Posts
    243
    Location
    Hi elmnas,

    It depends on what you are going to do within the loop?
    As a start, you could look at a If...End If loop directly inside the For...Next loop.
    Perhaps something along the lines of if the column is hiiden then ignore that column and move onto the next.

    I hope this gives you a start point.
    -----------------------------------------∏-

    12:45, restate my assumptions.
    Mathematics is the language of nature.
    Everything around us can be represented and understood through numbers.
    If you graph the numbers of any system, patterns emerge. Therefore, there are patterns everywhere in nature.

    -----------------------------------------∏-

  3. #3
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location
    I gonna do a search and replace

        Dim wks         As Worksheet
        Dim fndList     As Variant
        Dim rplcList    As Variant
        
        Dim x           As Long
        
        
        
      Set wks = ActiveWorkbook.ActiveSheet
        
        fndList = Array("ä", "ö", "ü", "Ä", "Ö", "Ü", "ß")
        rplcList = Array("ä", "ö", "ü", "Ä", "Ö", "Ü", "ß")
        Application.ScreenUpdating = False
        
          With wks
    
    
            For x = LBound(fndList) To UBound(fndList)
                ActiveSheet.Cells.Replace.Replace what:=fndList(x), replacement:=rplcList(x), lookat:=xlPart
            Next x
    
    
        
        Application.ScreenUpdating = True
        Set wks = Nothing
        Erase fndList
        Erase rplcList

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Not tested, but maybe something like this


    Option Explicit
    Sub test()
        Dim r As Range
        Dim x As Long
        Dim fndList(1 To 10) As String, rplcList(1 To 10) As String
        
        'test data
        ActiveSheet.Range("A1:Z26").Value = 123
        ActiveSheet.Columns(5).Hidden = True
        ActiveSheet.Columns(10).Hidden = True
        ActiveSheet.Columns(15).Hidden = True
        
        On Error Resume Next
        With ActiveSheet
            Set r = Intersect(.UsedRange, .UsedRange.SpecialCells(xlCellTypeVisible))
        End With
        On Error GoTo 0
        
        If r Is Nothing Then Exit Sub
        
         MsgBox r.Address
         
         For x = LBound(fndList) To UBound(fndList)
            r.Replace what:=fndList(x), replacement:=rplcList(x), lookat:=xlPart
        Next x
         
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

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