+ Reply to Thread
Results 1 to 9 of 9

Help with loops

  1. #1
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    Help with loops

    Dear all,

    Im having issues to make my code run in a loop. However it doesnt work. Could you please let me know why is not working?*and how it should be to work? The code is really simple, i want to make some if statements on column B and if they are true to fill the column D. I?*just want to make it looping but i cant find the error.....

    Your support is much appreciated,
    Attached Files Attached Files

  2. #2
    Forum Expert Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,432

    Re: Help with loops

    There are so many more simplistic solutions...But for this purpose...I'm off to bed...will post others in AM...
    Or OP's might jump in...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hello, try this !


    Quote Originally Posted by zoepal View Post
    Could you please let me know why is not working?
    'Cause your Vretail variable content has no sense as allocated outside the loop …


    Quote Originally Posted by zoepal View Post
    and how it should be to work?
    If you really want to use a loop :
    Please Login or Register  to view this content.
    But according to Excel basics it should be directly achieved without any VBA code just with a beginner level formula ‼

    When really a VBA procedure is necessary so rather than an useless loop just using a formula :

    PHP Code: 
    Sub Demo1()
       
    With Range("D2", [A1].End(xlDown)(14))
           .
    Formula "=IF(LEFT(B2,2)=""Fl"",""Outlet"",IF(LEFT(B2,3)=""PAY"",""Ecom"",IF(LEFT(B2,2)=""RB"",""Resurs Bank"","""")))"
           
    .Formula = .Value
       End With
    End Sub 
    Or when the direct formula evaluation is possible like in this VBA demonstration :

    PHP Code: 
    Sub Demo2()
        Const 
    "IF(LEFT(#,2)=""Fl"",""Outlet"",IF(LEFT(#,3)=""PAY"",""Ecom"",IF(LEFT(#,2)=""RB"",""Resurs Bank"","""")))"
        
    With Range("B2", [B1].End(xlDown)):  .Columns(3) = Evaluate(Replace(F"#", .Address)):  End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 01-21-2024 at 07:16 AM.

  4. #4
    Forum Expert Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,432

    Re: Help with loops

    Yep...These...were what I was referring to...

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Help with loops


    I was waiting you with a less basics formula - if all can be tested with only two letters - than the one in Demo1,
    I did not post it as it can't be directly evaluated …

  6. #6
    Registered User
    Join Date
    02-24-2021
    Location
    sweden
    MS-Off Ver
    2016
    Posts
    23

    Re: Help with loops

    Thanks to both, the formula worked good but it in reality is a much longer formula. Im testing around 11conditions so the formula looked quite bulkie. But if it runs faster then I will go for it. =)

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Help with loops


    So rather to hardcode the conditions why not just using a Settings worksheet holding a conversion table ?
    Then just using an easy VLOOKUP formula for example you can get rid of any VBA code !
    If really a VBA procedure is necessary then the formula should be easier than my demonstration …

  8. #8
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,665

    Re: Help with loops

    Try this code . You can add any number of conditions using ".ADD" command
    Please Login or Register  to view this content.
    Last edited by kvsrinivasamurthy; 01-22-2024 at 04:56 AM.
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,508

    Re: Help with loops

    VLOOKUP as per Marc's recommendation

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

+ 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. Loops within Loops - Populating all cells with same data
    By madrewise8 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-10-2021, 09:15 AM
  2. Loops within loops looping
    By Memphismark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2017, 12:21 PM
  3. Using For or Do Until loops
    By alb2p in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-14-2013, 04:52 PM
  4. [SOLVED] do loops
    By saravanan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-13-2006, 05:55 AM
  5. Loops
    By alecbowman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2006, 04:30 AM
  6. [SOLVED] For next loops
    By Kate in forum Excel General
    Replies: 5
    Last Post: 05-22-2006, 08:15 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