+ Reply to Thread
Results 1 to 3 of 3

Ifs, creating repetition and VBA

Hybrid View

seller7 Ifs, creating repetition and... 08-08-2022, 06:50 PM
6StringJazzer Re: Ifs, creating repetition... 08-08-2022, 08:27 PM
beyond Excel Re: Ifs, creating repetition... 08-08-2022, 09:40 PM
  1. #1
    Registered User
    Join Date
    10-12-2021
    Location
    Rio de Janeiro
    MS-Off Ver
    2016
    Posts
    13

    Ifs, creating repetition and VBA

    Thank you for the wonderful responses
    Attached Files Attached Files
    Last edited by seller7; 08-11-2022 at 01:47 PM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,995

    Re: Ifs, creating repetition and VBA

    Is there any reason this needs to use VBA? Here is a formula solution.

    Values as displayed
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Start
    0
    101
    201
    301
    401
    501
    2
    End
    100
    200
    300
    400
    500
    600
    3
    Number
    Repeat Across
    Amount
    4
    39
    1
    2,000
    2000
    5
    34
    5
    346
    346.2
    346.2
    346.2
    346.2
    346.2
    6
    359
    2
    9,994
    9994
    9994
    7
    102
    3
    7,218
    7218
    7218
    7218
    8
    405
    2
    5,995
    5995
    5995

    Underlying formulas
    A
    B
    C
    D
    E
    F
    G
    H
    I
    1
    Start
    0
    101
    201
    301
    401
    501
    2
    End
    100
    200
    300
    400
    500
    600
    3
    Number
    Repeat Across
    Amount
    4
    39
    1
    2000
    =IF(AND($A4>=D$1,$A4<=D$2),$C4,"")
    =IF(AND($A4>=E$1,$A4<=E$2),$C4,IF(AND($A4<=E$2,COUNTIF($D4:D4,">0")<$B4),$C4,""))
    =IF(AND($A4>=F$1,$A4<=F$2),$C4,IF(AND($A4<=F$2,COUNTIF($D4:E4,">0")<$B4),$C4,""))
    =IF(AND($A4>=G$1,$A4<=G$2),$C4,IF(AND($A4<=G$2,COUNTIF($D4:F4,">0")<$B4),$C4,""))
    =IF(AND($A4>=H$1,$A4<=H$2),$C4,IF(AND($A4<=H$2,COUNTIF($D4:G4,">0")<$B4),$C4,""))
    =IF(AND($A4>=I$1,$A4<=I$2),$C4,IF(AND($A4<=I$2,COUNTIF($D4:H4,">0")<$B4),$C4,""))
    5
    34
    5
    346.153846153846
    =IF(AND($A5>=D$1,$A5<=D$2),$C5,"")
    =IF(AND($A5>=E$1,$A5<=E$2),$C5,IF(AND($A5<=E$2,COUNTIF($D5:D5,">0")<$B5),$C5,""))
    =IF(AND($A5>=F$1,$A5<=F$2),$C5,IF(AND($A5<=F$2,COUNTIF($D5:E5,">0")<$B5),$C5,""))
    =IF(AND($A5>=G$1,$A5<=G$2),$C5,IF(AND($A5<=G$2,COUNTIF($D5:F5,">0")<$B5),$C5,""))
    =IF(AND($A5>=H$1,$A5<=H$2),$C5,IF(AND($A5<=H$2,COUNTIF($D5:G5,">0")<$B5),$C5,""))
    =IF(AND($A5>=I$1,$A5<=I$2),$C5,IF(AND($A5<=I$2,COUNTIF($D5:H5,">0")<$B5),$C5,""))
    6
    359
    2
    9993.5
    =IF(AND($A6>=D$1,$A6<=D$2),$C6,"")
    =IF(AND($A6>=E$1,$A6<=E$2),$C6,IF(AND($A6<=E$2,COUNTIF($D6:D6,">0")<$B6),$C6,""))
    =IF(AND($A6>=F$1,$A6<=F$2),$C6,IF(AND($A6<=F$2,COUNTIF($D6:E6,">0")<$B6),$C6,""))
    =IF(AND($A6>=G$1,$A6<=G$2),$C6,IF(AND($A6<=G$2,COUNTIF($D6:F6,">0")<$B6),$C6,""))
    =IF(AND($A6>=H$1,$A6<=H$2),$C6,IF(AND($A6<=H$2,COUNTIF($D6:G6,">0")<$B6),$C6,""))
    =IF(AND($A6>=I$1,$A6<=I$2),$C6,IF(AND($A6<=I$2,COUNTIF($D6:H6,">0")<$B6),$C6,""))
    7
    102
    3
    7217.93076923077
    =IF(AND($A7>=D$1,$A7<=D$2),$C7,"")
    =IF(AND($A7>=E$1,$A7<=E$2),$C7,IF(AND($A7<=E$2,COUNTIF($D7:D7,">0")<$B7),$C7,""))
    =IF(AND($A7>=F$1,$A7<=F$2),$C7,IF(AND($A7<=F$2,COUNTIF($D7:E7,">0")<$B7),$C7,""))
    =IF(AND($A7>=G$1,$A7<=G$2),$C7,IF(AND($A7<=G$2,COUNTIF($D7:F7,">0")<$B7),$C7,""))
    =IF(AND($A7>=H$1,$A7<=H$2),$C7,IF(AND($A7<=H$2,COUNTIF($D7:G7,">0")<$B7),$C7,""))
    =IF(AND($A7>=I$1,$A7<=I$2),$C7,IF(AND($A7<=I$2,COUNTIF($D7:H7,">0")<$B7),$C7,""))
    8
    405
    2
    5995
    =IF(AND($A8>=D$1,$A8<=D$2),$C8,"")
    =IF(AND($A8>=E$1,$A8<=E$2),$C8,IF(AND($A8<=E$2,COUNTIF($D8:D8,">0")<$B8),$C8,""))
    =IF(AND($A8>=F$1,$A8<=F$2),$C8,IF(AND($A8<=F$2,COUNTIF($D8:E8,">0")<$B8),$C8,""))
    =IF(AND($A8>=G$1,$A8<=G$2),$C8,IF(AND($A8<=G$2,COUNTIF($D8:F8,">0")<$B8),$C8,""))
    =IF(AND($A8>=H$1,$A8<=H$2),$C8,IF(AND($A8<=H$2,COUNTIF($D8:G8,">0")<$B8),$C8,""))
    =IF(AND($A8>=I$1,$A8<=I$2),$C8,IF(AND($A8<=I$2,COUNTIF($D8:H8,">0")<$B8),$C8,""))
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Ifs, creating repetition and VBA

    Hi. A solution with VBA:

    Sub Macro1()
    Dim mCell As Range, Rng As Range
    Set Rng = Range("D1", Range("D1").End(xlToRight))
    For Each mCell In Range("A4", Range("A3").End(xlDown))
      Cells(mCell.Row, Rng(WorksheetFunction.Match(mCell, Rng, 1)).Column).Resize(, mCell(, 2)) = mCell(, 3)
    Next
    End Sub
    Attached Files Attached Files
    Last edited by beyond Excel; 08-08-2022 at 09:46 PM.

+ 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. [SOLVED] VBA for all possible combinations without repetition
    By McGyver270 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 02-03-2021, 05:37 AM
  2. [SOLVED] Sum without repetition
    By ratkiller in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-19-2013, 09:20 AM
  3. [SOLVED] Repetition
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 04-29-2012, 06:55 PM
  4. Sampling Without Repetition
    By Provoxt in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-13-2010, 10:23 AM
  5. Repetition
    By EAMOG in forum Excel General
    Replies: 5
    Last Post: 12-15-2008, 06:37 PM
  6. Repetition
    By filmor in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-06-2008, 02:55 AM
  7. Repetition of Code
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2006, 11:55 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