Consulting

Results 1 to 5 of 5

Thread: Change VBA from AutoFill to FillDown

  1. #1
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location

    Change VBA from AutoFill to FillDown

    Hello,

    I have a code that is working fine, the only issue i have with it is that it Autofills and increments the value. I want it to just fill down with the same data. Can you please help me make this change, and a short explanation of why would be awesome, if not its ok.

    .Cells(i, "A").Resize(, 24).AutoFill .Cells(i, "A").Resize(cntNums, 24)
    .Cells(i, "Z").Resize(, 12).AutoFill .Cells(i, "Z").Resize(cntNums, 12)

    These are the lines i need changed to FillDown

    Here is what I currently have:

    Public Sub BasicLoop()
        Dim rowLast As Long
        Dim cntNums As Long
        Dim ary As Variant
        Dim i As Long
         
        Application.ScreenUpdating = False
         
        With ActiveSheet
             
            rowLast = .Cells(.Rows.Count, "Y").End(xlUp).Row
            For i = rowLast To 5 Step -1
                 
                If InStr(.Cells(i, "Y").Value, ";") > 0 Then
                     
                    ary = Split(.Cells(i, "Y").Value, ";")
                    cntNums = UBound(ary) - LBound(ary) + 1
                    .Rows(i + 1).Resize(cntNums - 1).Insert
                    .Cells(i, "A").Resize(, 24).AutoFill .Cells(i, "A").Resize(cntNums, 24)
                    .Cells(i, "Y").Resize(cntNums) = Application.Transpose(ary)
                    .Cells(i, "Z").Resize(, 12).AutoFill .Cells(i, "Z").Resize(cntNums, 12)
                End If
            Next i
        End With
         
        Application.ScreenUpdating = True
    End Sub
    Thank you for your help!!
    Last edited by Zlerp; 09-12-2014 at 07:49 AM.

  2. #2
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location
    Figured it out!! I need to declare the type of Autofill i want!

    .Cells(i, "A").Resize(, 24).AutoFill .Cells(i, "A").Resize(cntNums, 24), Type:=xlFillColumn

  3. #3
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    No, you should add code tags around VBA code in your post first !

  4. #4
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location
    Thanks for the Info snb!

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    That really makes a difference in readability !

Posting Permissions

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