+ Reply to Thread
Results 1 to 6 of 6

Autofill formulas in Range

  1. #1
    Registered User
    Join Date
    08-16-2016
    Location
    UK
    MS-Off Ver
    7
    Posts
    3

    Autofill formulas in Range

    Hello,

    New to VBA and having difficulties with the following routine.

    I extract a csv file from string that I generate in a cell in G15 (sheet "Macro"). I need to clear all contents in a sheet in this workkbook called "data 1". I then need to copy the contents of the target sheet into this sheet. Where the data ends (after column "AO") I then need to create some formulas in the next four columns and pull those formulas down to as far as there is data in column A.

    The code here has a couple of issues. Mainly this reference:

    ThisWorkbook.Sheets("Data1").lastrow = Range("A" & Rows.Count).End(xlUp).Row



    Any help/guidance apprecaited.

    '''''''''''''''''''''''''''''''''''''''''''''''

    Sub Import_Rds()
    Dim lastrow As Long
    Dim RdsFile As String

    Application.ScreenUpdating = False
    Application.CutCopyMode = False

    '************************DATA1 RDS grab******************************

    ‘Retrieves source file to open for directory stored in G15 on “Macro” sheet

    RdsFile = Range("G15").Value
    Workbooks.Open Filename:=RdsFile

    ThisWorkbook.Sheets("Data1").Cells.ClearContents
    ActiveWorkbook.ActiveSheet.Range("A1:AO10000").Copy
    Close
    ThisWorkbook.Sheets("Data1").Range("A1:AO10000").PasteSpecial xlPasteValues

    'Destination sheet - Add Bloomberg formulas and fill down to the formulas to range in column A

    ThisWorkbook.Sheets("Data1").lastrow = Range("A" & Rows.Count).End(xlUp).Row
    Range("AP2").Formula = "=IF(O2=""Equity"",BDP(K2,""CRNCY""),"" - "" "
    Range("AP2").AutoFill Destination:=Range("AP2:AP" & lastrow), Type:=xlFillDefault

    ThisWorkbook.Sheets("Data1").lastrow = Range("A" & Rows.Count).End(xlUp).Row
    Range("AQ2").Formula = "=IF(O2=""Equity"",BDP(K2,""rel_index""),"" - "" "
    Range("AQ2").AutoFill Destination:=Range("AQ2:AQ" & lastrow), Type:=xlFillDefault

    ThisWorkbook.Sheets("Data1").lastrowRange("A" & Rows.Count).End(xlUp).Row
    Range("AR2").Formula = "=IF(O2=""Equity"",BDP(K2,""GICS_industry_name""),"" - "" "
    Range("AR2").AutoFill Destination:=Range("AR2:AR" & lastrow), Type:=xlFillDefault

    ThisWorkbook.Sheets("Data1").lastrow.Range("A" & Rows.Count).End(xlUp).Row
    Range("AS2").Formula = "=AD2"
    Range("AS2").AutoFill Destination:=Range("AS2:AR" & lastrow), Type:=xlFillDefault

    End sub


    Example Formulas

    ' =IF($O2="Equity",BDP(K2,"CRNCY"),"-"
    '=IF($O2="Equity",BDP($K2,"rel_index"),"-")
    '=IF($O2="Equity",BDP($K2,"GICS_industry_name"),"-")
    '=AD2

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Autofill formulas in Range

    That one line should be
    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Last edited by davesexcel; 08-16-2016 at 01:52 PM.

  3. #3
    Registered User
    Join Date
    08-16-2016
    Location
    UK
    MS-Off Ver
    7
    Posts
    3

    Re: Autofill formulas in Range

    Many thanks, the code works. now its we're having issues on Range("AP2").Formula = "=IF(O2=""Equity"",BDP(K2,""CRNCY""),"" - "" "
    Also, is my handling of Thisworkbook and Activeworkbook correct?

    Appreciate the help

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Autofill formulas in Range

    What would the formula look like normally?

    If you are only on one workbook, "ThisWorkbook" or "Activeworkbook" would be assumed and would normally just be required if you are manipulating a different workbook.

  5. #5
    Registered User
    Join Date
    08-16-2016
    Location
    UK
    MS-Off Ver
    7
    Posts
    3
    Quote Originally Posted by davesexcel View Post
    What would the formula look like normally?

    If you are only on one workbook, "ThisWorkbook" or "Activeworkbook" would be assumed and would normally just be required if you are manipulating a different workbook.
    Hi,

    Would look like:
    =IF($O2="Equity",BDP(K2,"CRNCY"),"-"

    If o2 has equity in it then call bdp (api) referencing the data in K2.

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,483

    Re: Autofill formulas in Range

    I am not sure what bdp is, possibly a function?

+ 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. Autofill formulas with across multiple columns with variable range
    By jstan7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2015, 06:39 PM
  2. Autofill Formulas
    By edwinhwhw87 in forum Excel General
    Replies: 14
    Last Post: 08-18-2014, 02:07 AM
  3. Want to autofill cells with formulas in a range with a dynamic numbe of rows
    By hgeo24 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-06-2014, 05:59 PM
  4. [SOLVED] Need help today PLEASE. Autofill vba code from one range (formulas) down
    By aehartle in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-31-2013, 09:22 PM
  5. [SOLVED] Very small AutoFill macro showing "AutoFill methode of range class failed" why ?
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2013, 10:21 PM
  6. Using Autofill to copy a range of formulas
    By GregF56 in forum Excel General
    Replies: 3
    Last Post: 09-19-2011, 08:53 AM
  7. AutoFill w/formulas
    By JamesElting in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 PM

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