Consulting

Results 1 to 3 of 3

Thread: Autofill down based on two conditions

  1. #1
    VBAX Regular
    Joined
    May 2009
    Posts
    76
    Location

    Autofill down based on two conditions

    Need some assistance with vba for Auto-filling a formula in column "A" down based on two conditions.

    Condition #1: Autofill formula down starts when “Claim” is located in Column “A” and ends when "totals" is located in Column "A" and repeats until the last "Claim" and "totals" is located.

    I'm using the below code for a similar issue that might be a good start.


    See attached worksheet. [VBA]
    ' hiker95, 02/10/2012
    Dim C As Range, firstaddress As String
    Application.ScreenUpdating = False
    With Columns("G")
    Set C = .Find("Amount X's of", LookIn:=xlValues, LookAt:=xlWhole)
    If Not C Is Nothing Then
    firstaddress = C.Address
    Do
    With C.Offset(1)

    .Value = UserForm3.am1.Value

    End With
    Set C = .FindNext(C)
    Loop While Not C Is Nothing And C.Address <> firstaddress
    End If
    End With
    Application.ScreenUpdating = True
    End Sub[/VBA]
    Attached Files Attached Files

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]Sub Test()
    Dim c As String, t As String
    Dim r As Range
    Dim FR As Range
    Dim Tp As Range, Bm As Range
    Dim Cnt As Long


    Set r = Columns(1)
    c = "Claim"
    t = "TOTALS"
    Cnt = Application.CountIf(r, c)

    Set Tp = Cells(1, 1)
    Do Until i = Cnt
    Set Tp = r.Find(c, Tp)(2)
    Set Bm = r.Find(t, Tp)(0)
    Set FR = Range(Tp, Bm)
    FR(1).AutoFill Destination:=FR, Type:=xlFillSeries
    i = i + 1
    Loop
    End Sub[/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Autofill needs a seed cell. Is yours just filling down from the cell under Claim?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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