+ Reply to Thread
Results 1 to 18 of 18

Looping through columns

  1. #1
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Looping through columns

    Hi,

    I kinda stuck on how to get this to work. I want to loop through column C to check for matches, but if it appears more then 2 times ignore it.

    If it matches within the column C then check if column D also matches if it does concat column B and "1C" at the end. (1C = 1 colour)

    If it doesn't match then concat column B and "2C" at the end. (2C = 2 colours)

    If it doesn't match in column C then concat column B with column D but only the first 2 letters of column D.

    I'd attached an example workbook of before.

    Thanks
    Attached Files Attached Files
    Last edited by HXIO; 06-01-2019 at 11:28 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Looping through col

    What does "col" mean in your thread title?

  3. #3
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through col

    @ Pepe Le Mokko

    It’s means column I forgot to reword it back to column.

  4. #4
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Looping through col

    Perhaps adapt your thread title then?

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831
    (removed 'cause of post #10 as the initial attachment not matches the initial explanation ‼ As usually in that case I do … nothing !)
    Last edited by Marc L; 06-04-2019 at 07:53 AM.

  6. #6
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through columns

    @ Marc L

    Thanks for the help if possible can you go through the code with me. There's quite a few things I don't quite understand in the code.

    Thanks

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

    Arrow

    Thanks for the rep' !

    If you don't find enough information in VBA inner help (as almost all is there) so ask for any specific point …

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

    Re: Looping through columns

    Hi HXIO
    but if it appears more then 2 times ignore it.
    If this is the case then why is your output as such...This number appears 4 times in Col C

    Untitled.png

    Surely they must be blank...
    Please Login or Register  to view this content.
    Last edited by sintek; 06-03-2019 at 04:29 PM.
    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 star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

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

    Arrow

    Quote Originally Posted by sintek View Post
    This number appears 4 times in Col C
    Yes I saw that too & had the same thought as yours but with the attachment I did not keep that rule …

  10. #10
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through columns

    @ sintek

    Thanks for pointing this out, and yes you are right it should be blank.

    Because I want any values in Column C appear more than 2 times on another columns with different rules.

    I will upload a workbook later with other rules.

  11. #11
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through columns

    @Marc L and sintek

    Both codes does the job and works great is there any chance to incorporate this into the exiting codes?

    If I want to include column C values appearing more than 2 times as well in a different column with these rules below.

    If values appear 3 or more with same colour concat column B and add “1C” at the end same as the rules with values appearing 2 times. However, if the first 4-5 string before the first “-“ is different then that will be concat as well.

    If values appear 3 or more with different colours for example if there’s 2 colours then add “2C” or "3C" and "4C" at the end and if it’s 3 or 4 it will be the same rules but there will be more combinations. If values appear more than 4 times it will be ignore.

    Pretty much whenever the values increase in column C, then there will be more combinations added on.

    I’d include another workbook with different combinations.
    Attached Files Attached Files

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

    Re: Looping through columns

    Your outputs in After sheet are incorrect as per original requirement...Please correct all outputs as to requirement and upload correct resultant file...
    P919-76-15 0020344849 RED P919-76-15+P919C-56-02-1C

  13. #13
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through columns

    @sintek

    Apologised for the late reply, please see the amended example.
    Attached Files Attached Files

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

    Arrow


    Still errors in last attachment (rows #13 & 26) so check & correct !
    Last edited by Marc L; 06-16-2019 at 09:02 PM. Reason: misreading …

  15. #15
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through columns

    @Marc L

    Thanks for pointing it out I'd correct line 13 as for line 26 it should be correct.
    Attached Files Attached Files

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

    Question


    Have you this time well think about your need like you must before creating any thread ?
    'Cause it will be my last code …

  17. #17
    Forum Contributor
    Join Date
    03-02-2018
    Location
    england
    MS-Off Ver
    2016
    Posts
    156

    Re: Looping through columns

    @Marc L

    Yes this is what I needed there won't be anymore changes. I will make sure to think well next time before I starting any new thread nest time. Thanks for being patient with me.

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

    Cool


    So according to your post #15 attachment, the best is to paste this code to the worksheet module :

    PHP Code: 
    Sub Demo2()
       Const 
    "SUMPRODUCT(1/COUNTIF(D#:D¤,D#:D¤))""-""+"
         
    Dim R&, T$, B$(), C(), F&, L&, S$, VW()
             
    1
             Application
    .ScreenUpdating False
        With 
    [A1].CurrentRegion
            
    .Columns("E:F").Clear
            
    .Sort [C1], xlAscendingHeader:=xlYes
        End With
             T 
    = [B2].Value2
        
    Do
                
    1
            
    If Cells(13).Value2 Cells(R3).Value2 Then
                    ReDim B
    (1 To 1), C(1 To 1)
                    
    R
                    L 
    InStrRev(TM)
                    
    B(1) = Left$(TL)
                    
    C(1) = Array(Mid$(T1))
                Do
                        
    1
                        T 
    Cells(R2).Value2
                        L 
    InStrRev(TM)
                        
    Left$(TL)
                        
    Mid$(T1)
                        
    Application.Match(SB0)
                    If 
    IsError(VThen
                        L 
    UBound(B) + 1
                        ReDim Preserve B
    (1 To L), C(1 To L)
                        
    B(L) = S
                        C
    (L) = Array(T)
                    ElseIf 
    IsError(Application.Match(TC(V), 0)) Then
                        W 
    C(V)
                        
    ReDim Preserve W(UBound(W) + 1)
                        
    W(UBound(W)) = T
                        C
    (V) = W
                    End 
    If
                
    Loop While Cells(13).Value2 Cells(R3).Value2
                    
    For 1 To UBound(B):  B(L) = B(L) & Join(C(L), P):  Next
                    Cells
    (F- (1)).Value2 Join(BP) & Evaluate(Replace$(Replace$(D"#"F), "¤"R)) & "C"
            
    Else
                
    Cells(R5).Value2 Left$(Cells(R4).Value22)
            
    End If
                   
    Cells(12).Value2
        Loop Until T 
    ""
             
    Application.ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

+ 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] looping
    By newtovba99 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2019, 11:18 AM
  2. Looping through each row
    By dusto in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-07-2014, 09:40 PM
  3. Do Until Looping (not looping through all other columns)
    By orle8050 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-11-2013, 10:37 AM
  4. [SOLVED] vba looping
    By amu in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-24-2012, 01:25 PM
  5. [SOLVED] VBA Looping with Ifs
    By harrison298 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2012, 04:35 AM
  6. vba looping
    By amu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2012, 03:36 AM
  7. [SOLVED] Looping
    By teresa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-30-2005, 09:05 PM

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