+ Reply to Thread
Results 1 to 2 of 2

VBA to Autofill on Filtered Columns only

Hybrid View

  1. #1
    Registered User
    Join Date
    06-20-2024
    Location
    London
    MS-Off Ver
    365
    Posts
    1

    Unhappy VBA to Autofill on Filtered Columns only

    Hi, I'm trying to create macros to analyze my research project data.
    I'm new to VBA and don't know much so I try to record macros if it works and then get the base code and tweak it.

    I have filtered my column B ("animal") to show only "z011" and "z012". I assigned the value "Control" in "C12" (First cell in this case). I need to assign these filtered rows as "Control" in Column C from the first cell ("C12" in this case), till the last cell.

    This is my code currently that i managed to work out from various threads here and there. However I'm not sure what's wrong as it changes my entire sheet cells to "Control".

    Sub Macrotest2()
    '
    ' Macrotest2 Macro
    '
    
    '
        ActiveSheet.Range("$A$1:$AO$12598").AutoFilter Field:=2, Criteria1:="=z011" _
            , Operator:=xlOr, Criteria2:="=z012"
        ActiveSheet.Range("$A$1:$AO$12598").AutoFilter Field:=2, Criteria1:="=z011" _
            , Operator:=xlOr, Criteria2:="=z012"
        Range("C12").Select
        ActiveCell.FormulaR1C1 = "Control"
        Lastrow = Range("C" & Rows.Count).End(xlUp).Row
        Range("C12:C" & Lastrow).SpecialCells(xlCellTypeVisible) = Range("C12").Value
        
        
    End Sub

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: VBA to Autofill on Filtered Columns only

    Hi akshi7
    Welcome to the Forum...
    Please upload a sample depicting actual file setup showing before | after expected result...
    This will help members understand and offer the best possible solution...
    Last edited by Sintek; 06-20-2024 at 10:54 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] AutoFill on a Filtered Range
    By Rabbitoh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-29-2023, 09:17 PM
  2. Facing an issue to correctly autofill according to filtered data with macros
    By immillen in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2020, 08:32 PM
  3. [SOLVED] Autofill Two Columns Over Twenty Four Columns
    By Allienne in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-21-2019, 01:28 PM
  4. [SOLVED] Sorting filtered Columns by 2 different columns Office 2010
    By meabrams in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-12-2015, 02:59 AM
  5. VBA code to hide filtered columns (simple table 5 rows / 6 columns wide)
    By e2010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-18-2014, 02:41 PM
  6. [SOLVED] Autofill across columns
    By ablacksheep in forum Excel General
    Replies: 5
    Last Post: 03-25-2014, 11:06 AM
  7. [SOLVED] VBA to autofill columns
    By Doctor_H in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-26-2013, 06:01 PM

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