+ Reply to Thread
Results 1 to 2 of 2

Return specific values from one workbook to another, in specific cells

  1. #1
    Registered User
    Join Date
    04-12-2013
    Location
    london
    MS-Off Ver
    Excel 2010
    Posts
    7

    Return specific values from one workbook to another, in specific cells

    Hi Guys

    I am very stuck and I would appreciate your help..

    I have 2 workbooks "Project Financial Summary" and "Cost Transactions By Cost Code and Project"
    I have "Project Financial Summary"open

    I need to:
    -Find specific cell values in "Cost Transactions By Cost Code and Project" and inserted into specific cells in "Project Financial Summary"
    -In particular: in "Cost Transactions By Cost Code and Project"
    -every time the word "Description" is next to the word" Material", find the next word "Project Total" and return the value next to it to cell "E8"
    in "Project Financial Summary"
    -every time the word "Description" is next to the word" Expenses", find the next word "Project Total" and return the value next to it to cell "E9"
    in "Project Financial Summary"
    -Save "Project Financial Summary" and close "Cost Transactions By Cost Code and Project"


    I here attach the two workbooks.
    I know it's a bit complex but I hope someone can help me...also here attached my macro attempts..! (I know it's a mess..!!)

    Thanks everybody..


    Workbooks.Open Filename:= _
    "C:\Users\RTR\Documents\Financial Summary\Cost Transactions By Cost Code and Project (Sage).xlsx"
    ActiveWindow.Visible = False
    Windows("Cost Transactions By Cost Code and Project (Sage).xlsx").Activate

    ' Declare variables used in this function
    Dim foundIt As Boolean
    Dim total As Double
    Dim NoOfColumns As Integer
    Dim NoOfRows As Integer
    Dim SectionText As String
    Dim wb As Workbooks
    Dim ws As Worksheet

    ' Initialise variables
    foundIt = False
    total = 0
    NoOfColumns = 15
    NoOfRows = 300
    SectionText = "Material"

    ' Loop through columns A to Z
    For j = 1 To NoOfColumns
    ' Loop through rows 1 to 500
    For i = 1 To NoOfRows
    ' If the current cell is "Description" and the cell 2 columns on is "Material"
    If ThisWorkbook.ActiveSheet.Cells(i, j) = "Description" And ThisWorkbook.ActiveSheet.Cells(i, j + 2) = SectionText Then
    ' Flag that we have found the right section
    foundIt = True
    End If
    ' If we are in the right section and the current cell is the "project total"
    If ThisWorkbook.ActiveSheet.Cells(i, j) = "Project Total" And foundIt = True Then
    ' Get the value from 2 cells on
    total = ThisWorkbook.ActiveSheet.Cells(i, j + 2)
    ' debug show the captured value
    MsgBox "Material £ " & total
    ' make sure we don't over write this number with data from the next section
    ' by killing the section found flag
    foundIt = False
    End If
    Next
    Next

    ' Initialise variables
    foundIt = False
    total = 0
    NoOfColumns = 15
    NoOfRows = 500
    SectionText = "Expenses"

    ' Loop through columns A to Z
    For j = 1 To NoOfColumns
    ' Loop through rows 1 to 500
    For i = 1 To NoOfRows
    ' If the current cell is "Description" and the cell 2 columns on is "Expenses"
    If ThisWorkbook.ActiveSheet.Cells(i, j) = "Description" And ThisWorkbook.ActiveSheet.Cells(i, j + 2) = SectionText Then
    ' Flag that we have found the right section
    foundIt = True
    End If
    ' If we are in the right section and the current cell is the "project total"
    If ThisWorkbook.ActiveSheet.Cells(i, j) = "Project Total" And foundIt = True Then
    ' Get the value from 2 cells on
    total = ThisWorkbook.ActiveSheet.Cells(i, j + 2)
    ' debug show the captured value
    MsgBox "Expenses £ " & total
    ' make sure we don't over write this number with data from the next section
    ' by killing the section found flag
    End If
    Next
    Next




    ' Columns("N:P").Select
    With Selection
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False


    End With
    Sheets("C:\Users\RTR\Documents\Financial Summary\Project Financial Summary.xlsx").Activate
    Range("E8").Select
    ActiveCell.FormulaR1C1 = _
    "='[Cost Transactions By Cost Code and Project.xlsm]Cost Transactions By Cost Code'!R17C14"
    Range("E9").Select
    ActiveCell.FormulaR1C1 = _
    "='[Cost Transactions By Cost Code and Project.xlsm]Cost Transactions By Cost Code'!R27C14"
    Range("E10").Select
    End Sub

  2. #2
    Valued Forum Contributor tehneXus's Avatar
    Join Date
    04-12-2013
    Location
    Hamburg, Germany
    MS-Off Ver
    Work: MS-Office 2010 32bit @ Win8 32bit / Home: MS-Office 2016 32bit @ Win10 64bit
    Posts
    944

    Re: Return specific values from one workbook to another, in specific cells

    Hello,

    please use CODE-Tags to post any kind of code in your posts: http://www.excelforum.com/misc.php?do=bbcode#code
    Please use [CODE]-TAGS
    When your problem is solved mark the thread SOLVED
    If an answer has helped you please click to give reputation
    Read the FORUM RULES

+ 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