+ Reply to Thread
Results 1 to 2 of 2

for loop with if

Hybrid View

michal.mandak.89 for loop with if 07-28-2022, 07:28 AM
TMS Re: for loop with if 07-28-2022, 09:32 AM
  1. #1
    Registered User
    Join Date
    10-13-2021
    Location
    Slovakia
    MS-Off Ver
    365
    Posts
    7

    for loop with if

    Hi, I would like ask you to one multiple loop with if. I have to sum with two criteria. First is ID and second is date. I prepare this vba code but doesn't work:
    a,b,dd are range where are items to sum or range of criteria.
    I are rows with ID
    Z are rows with date
    if ID (name) is same in two table then is necessary have to same date and then make sum for these ID.

    For i = 14 To finalrow
    For z = 3 To 9

    If ws_target.Cells(i, 1) > " " Then
    ws_target.Cells(i10) = Application.WorksheetFunction.SumIfs(ws_source.range(b), ws_source.range(a), ws_target.Cells(i, 1), ws_source(dd), ws_target.Cells(z, 4))
    next z
    end if
    next I

    could you please help me?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,440

    Re: for loop with if

    This
     If ws_target.Cells(i, 1) > " " Then
    is checking if the cell has a single space in it, not if it is empty. Is that what you want?

    Why don't you just use SUMIFS or a Pivot Table? With 365, you could possibly use the UNIQUE and/or FILTER functions.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


+ 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. Loop through emails to find Email today, if not found loop Date -1
    By lougs7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-29-2020, 12:48 PM
  2. Replies: 13
    Last Post: 07-08-2018, 05:22 AM
  3. [SOLVED] (Beginner help) For loop inside do loop that displays information from reference sheet.
    By lediable007 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-08-2016, 03:20 PM
  4. [SOLVED] Auto email loop with formatted table data breaking on second loop VBA
    By Who_else in forum Excel General
    Replies: 6
    Last Post: 03-24-2016, 06:22 AM
  5. [SOLVED] VBA to loop within a loop of multiple blocks of data (currentregion) ... Expert needed
    By Jim885 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-20-2016, 08:28 PM
  6. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  7. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM

Tags for this Thread

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