+ Reply to Thread
Results 1 to 3 of 3

Copy to Visible cells after filter

Hybrid View

  1. #1
    Forum Contributor vandanavai's Avatar
    Join Date
    09-04-2006
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Copy to Visible cells after filter

    Hello

    I need Vb code to do following
    1) I have data in A18:F5000
    2) I have filtered it based on Column D
    Up to this level I could write vb code using recording macro.
    Now I will Put formula in G18 and want to copy it to G19:G5000 but only to visible cells after filter.

    Plese help. Hoe to go about this?

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Copy to Visible cells after filter

    Your recorded code will need editing to something like this. I have assumed the header row is Row 1.
    OptionOption Explicit
    
    Sub AddFormula_FiltereRange()
        Const sCrit As String = "a"    '<- change date here
        Dim FilterData As Range
        Dim OldValue As String
        On Error GoTo exit_handler
        With ActiveSheet
            If .AutoFilterMode = False Then .Cells(1, 1).AutoFilter
            .Range("A1").AutoFilter Field:=4, Criteria1:="=" & sCrit
            ' On Error GoTo exit_handler
            Set FilterData = .Range("A1").CurrentRegion
            With FilterData
                OldValue = .Cells(1, 7).Value
                .Offset(1, 0).Resize(.Rows.Count - 1, _
                                     .Columns.Count).SpecialCells(xlCellTypeVisible).Select
                .Columns(7).Formula = "=5*5"
                .Cells(1, 7).Value = OldValue
            End With
    exit_handler:
            .AutoFilterMode = False
        End With
        On Error GoTo 0
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Contributor vandanavai's Avatar
    Join Date
    09-04-2006
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    256

    Re: Copy to Visible cells after filter

    Hello

    Thanks for help.
    It seems bit complicated.

+ 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