+ Reply to Thread
Results 1 to 3 of 3

MS Excel selection and autofill? VBA..

Hybrid View

  1. #1
    Registered User
    Join Date
    10-14-2013
    Location
    munich
    MS-Off Ver
    Excel 2010
    Posts
    11

    MS Excel selection and autofill? VBA..

    HI,
    I am trying to generate an autofill option.
    Need to do it on VBA. can you pls correct this code?

    The problem is I can select the entire column but cant autofill the other percentage cells using macro.
    here is the code:

    Sub percentage_col()
    Dim LastRow As Long
    With Worksheets("Sheet6")
    LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
    Range("F2:F" & LastRow).Select
    Range("F2").Select
    ActiveCell.FormulaR1C1 = "=(RC[-4]/RC[-2])*100"
    Selection.AutoFill Destination:=Range("F2:F5000"), Type:=xlFillDefault

    End With
    Range("F2:F" & LastRow).Select

    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: MS Excel selection and autofill? VBA..

    Hi, pranayttt,

    please note that you should wrap your procedure with code tags if shown here on Excel-Forum (according to Forum Rul #1)

    If you work with ActiveCell this will always work for the active sheet, if you use it inside a With-Statement you must make clear where itīs going to be applied (ActiveSheet without dot prior to the range/cell, referenced sheet with dot in front). You may generate the formula for all cells at once instead of creating it for one cell and then filldown:
    Sub Percentage_Col_re()
    Dim LastRow As Long
    With Worksheets("Sheet6")
      LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
      .Range("F2:F" & LastRow).FormulaR1C1 = "=(RC[-4]/RC[-2])*100"
    End With
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    10-14-2013
    Location
    munich
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: MS Excel selection and autofill? VBA..

    ty for your help.

+ 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] Selection Autofill to last row
    By arn0ldas in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-19-2013, 06:48 AM
  2. Complicated VBA change to text Selection.AutoFill Excel 2007
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-27-2012, 12:19 PM
  3. Autofill a Dynamic Selection
    By georgeanaprop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-05-2012, 12:36 PM
  4. Autofill selection down to last row
    By pluginguin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-03-2011, 11:04 AM
  5. AutoFill on selection
    By Desert Piranha in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-04-2006, 08:35 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