+ Reply to Thread
Results 1 to 2 of 2

Formula to add cells from external file

  1. #1
    Registered User
    Join Date
    07-15-2006
    Posts
    43

    Formula to add cells from external file

    Hi,

    I'm trying to write a formula with VBA to add data from cells from an external Excel file using the GetOpenFileName method.

    So far I keep encountering syntax errors.

    For example, I want the activecell formula to add (sum) data from an external file Sheet2, cell AL23; Sheet2, cell AT17; Sheet2, cellAT24, etc.

    Any help will be greatly appreciated, thanks!

  2. #2
    Registered User
    Join Date
    07-15-2006
    Posts
    43
    This is kind of what the VBA code I'm trying:

    Sub AutoPopulateTest()

    MsgBox "IN THE NEXT DIALOG BOX," & (Chr(13)) & (Chr(13)) & _
    "FIND THE EXCEL FILE & " & (Chr(13)) & (Chr(13)) & _
    "DOUBLE-CLICK ON IT TO" & (Chr(13)) & (Chr(13)) & _
    "AUTO-POPULATE THE TEST SHEET.", vbInformation

    TEST = ActiveWorkbook.Name

    'Get the Excel File
    BookA = Application.GetOpenFilename("Excel Workbook (*.xls), *.xls")

    If BookA <> False Then
    Workbooks.Open Filename:=BookA
    End If

    BookA = ActiveWorkbook.Name


    Windows(TEST).Activate
    Sheets("Sheet1").Range("C22").Select
    Windows(BookA).Activate
    Sheets("Sheet2").Select
    ActiveCell.Formula = '=sum(Workbooks([BookA]).Worksheets_
    ("Sheet2").Range("AL23"), Workbooks([BookA]).Worksheets("Sheet2").Range("AT17"), Workbooks([BookA]).Worksheets("Sheet2").Range("AT24"))'
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

    I realize it is not very good, but I needed some help. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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