+ Reply to Thread
Results 1 to 6 of 6

Substract values from two arrays and show in new sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    09-14-2012
    Location
    Oss, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Substract values from two arrays and show in new sheet

    I want to copy the the first sheet to a new sheet and then substract the values from the second sheet.
    The unique identifier in both sheet 1 and sheet 2 is in the first column. The values per week are in the column 4 until 30.
    Below a quick sample of my data.
    Who can help me out?

    Sheet 1 (source 1)
    wk1 wk2 wk3
    A x x 10 18 26
    B x x 11 19 27
    C x x 12 20 28
    D x x 13 21 29
    E x x 14 22 30
    F x x 15 23 31
    G x x 16 24 32
    H x x 17 25 33

    Sheet2 (source 2)
    wk1 wk2 wk3
    A x x 12 6 12
    G x x 1 7 13
    D x x 2 8 14
    H x x 3 9 35
    E x x 4 10 16
    F x x 5 11 17

    Sheet3 (result; [source1-source2])
    wk1 wk2 wk3
    A x x -2 12 0
    B x x 11 19 27
    C x x 12 20 28
    D x x 11 13 15
    E x x 10 12 14
    F x x 10 12 14
    G x x 15 17 19
    H x x 14 16 -2
    Attached Files Attached Files
    Last edited by paddy69; 09-14-2012 at 06:13 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Substract values from two arrays and show in new sheet

    help me attaching a sample file
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    09-14-2012
    Location
    Oss, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Substract values from two arrays and show in new sheet

    Sample attached:

    In the first sheet you will find the source data
    In the second sheet you will find the values in column D-G that need to be substracted from the values in sheet 1.
    In the third sheet I want to see the result. This sheet doesn't exist yet.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Substract values from two arrays and show in new sheet

    Sub b()
    Dim c As Range
    Set Sh1 = Sheets("Blad1")
    Set Sh2 = Sheets("Blad2")
    Set sh3 = Sheets("Blad3")
    repo = Sh2.Cells(1, 2)
    Sh1.UsedRange.Copy sh3.Range("A1")
    Set rng2 = Sh2.UsedRange.Resize(, 1).Offset(2, 0)
    rng2.Select
    With sh3
      lastrow = .Range("A" & .Rows.Count).End(xlUp).Row
      For j = 3 To lastrow
        ID = .Cells(j, 1).Value
        Set c = rng2.Find(ID, LookIn:=xlValues)
        If Not c Is Nothing Then
          .Cells(j, 4).Value = .Cells(j, 4).Value - Sh2.Cells(c.Row, 4).Value
          .Cells(j, 5).Value = .Cells(j, 5).Value - Sh2.Cells(c.Row, 5).Value
          .Cells(j, 6).Value = .Cells(j, 6).Value - Sh2.Cells(c.Row, 6).Value
        End If
      Next
    End With
    End Sub

  5. #5
    Registered User
    Join Date
    09-14-2012
    Location
    Oss, The Netherlands
    MS-Off Ver
    Excel 2003
    Posts
    10

    Re: Substract values from two arrays and show in new sheet

    Thanks Patel. One issue, if I'm not in sheet "Blad2" I get an error message on row "rng2.select". Thanks Again.

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Substract values from two arrays and show in new sheet

    remove rng2.select, it's only for testing

+ 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