+ Reply to Thread
Results 1 to 13 of 13

Matching Data - Loop

  1. #1
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28

    Matching Data - Loop

    Hi

    What I am trying to do is pretty simple (this is what I imagine)

    I have a 4 columns
    - the columns 1 and 2 contain a number of days and an associated number
    - the columns 3 and 4 contain a number of days and an associated number

    My formula should do this:
    - if the number of days (col 1 and 3) are the same, then multiply the number in col 3 and 4 together.
    - more specifically, for each number in col 1, the formula looks all matching values in col 3 and makes a simple calculation
    - result displayed in column 5

    Constraints
    - col 1 has more data than col 3
    - the data in both column are not sorted

    What I have so far:

    Dim x As Integer

    For x = 1 To 10 Step 1
    If Cells(x, 1) = Cells(x, 3).Value Then
    Cells(x, 5).Value = Cells(x, 3) * Cells(x, 4)
    End If
    Next x
    Could someone help me on this?
    Thanks a lot in advance
    Last edited by k21k; 09-05-2008 at 09:40 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Welcome to Exceltip forum

    Please take a couple of minutes and read the Forum Rules then wrap your VBA code (Rule 3)
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Valued Forum Contributor rwgrietveld's Avatar
    Join Date
    09-02-2008
    Location
    Netherlands
    MS-Off Ver
    XL 2007 / XL 2010
    Posts
    1,671

    re: Matching Data - Loop

    Why not just use:

    E1=IF(A1=C1;C1*D1;0)

    Gr,
    Ricardo
    Last edited by rwgrietveld; 09-05-2008 at 08:58 AM. Reason: multiply col 3 and 4 instead of 2 and 4

  4. #4
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,529
    Wrap code like this, click the # icon and paste the code
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    Hi Ricardo

    Actually, I want to write the formula because this example will be used to process a more complex task (launching a solver instead a doing a multiplication).

    do you have an idea about the VBA?

    Thanks a lot for your time

  6. #6
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    Hi Dave

    Your macro works, but applies the calculation only 1 time.
    Is it possible to make it work for all values in col 1 successively?

    Thanks in advance

  7. #7
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    Could you post a sample?

    I think you need to loop through your values in A and lookup values in C to find multiplicates - but I don't want to take time to build this because I'm not exactly sure what you need...

  8. #8
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    here is the file
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    k21k

    I asked you to read forum rules & wrap your VBA code

    following a moderators request is also listed listed in the rules

    I am closing this thread until you PM me that you have read the rules & will follow the rules


    Edit
    Thread re-opened as I have received a PM from k21k
    Last edited by mudraker; 09-05-2008 at 09:40 AM.

  10. #10
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    I have wrapped my code. Sorry for my mistake, will not happen again.
    Thanks for having reopened my thread.

    Is anyone able to help on this topic?
    Please have a look at the attached spreadsheet.
    The main issue is that the #days in the col 1&2 are matching, but not on the same rows.

    Thanks a lot in advance
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    09-05-2008
    Location
    London
    Posts
    28
    Could anyone help on this one?

  12. #12
    Forum Expert
    Join Date
    08-27-2008
    Location
    England
    MS-Off Ver
    2010
    Posts
    2,561
    This seems pretty straightforward but it's still not clear what you want:
    For day1 - 3, value 15, there are two values in Day2, values 12 and 24, - do you want:
    15*12*24
    (15*12) + (15*24)
    15*12, 15*24 adjacent
    ?

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

    Double Loop

    Quote Originally Posted by k21k View Post
    Could anyone help on this one?
    Hi Give this a go,
    Please Login or Register  to view this content.

+ 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. Count the data relevant to matching data
    By deepak_gl in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-25-2008, 02:01 AM
  2. How can I speed up this slow macro?
    By rs2k in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2008, 08:34 PM
  3. Matching data from one worksheet to another if 2 conditions are met
    By Neales in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-22-2008, 11:01 AM
  4. loop, matching data between ws
    By MDS in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-28-2007, 01:01 PM
  5. How to compare data in table and return sum of matching pairs?
    By Chris123 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-03-2007, 10:09 AM

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