+ Reply to Thread
Results 1 to 16 of 16

How to loop

  1. #1
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    How to loop

    Hi,
    I have this working code, and I am trying to do a loop for multiple columns in Sheet1 :
    Right now, the code takes the last value from column C, search in sheet "WebData (column "C") and get all findings in Sheet1, column "C". I am willing to do a loop with values from columns C:R and get findings in specific column. Example : if value in column C is "aaa" I need all "aaa" values from sheet WebData to be pasted in column "C", all "bbb" in column "D", and so on, for all columns, until "R".

    Can anyone point me in the right direction ?

    PHP Code: 
    Sub Search()
         
    Dim name As Stringname Sheets("Sheet1").Range("C" Rows.Count).End(xlUp)
         
    Dim rgSearch As Range
        Set rgSearch 
    Sheets("WebData").Range("C1:C5000")
         
    Dim cell As Range
        Set cell 
    rgSearch.Find(name)
         If 
    cell Is Nothing Then
            MsgBox 
    "Not found"
            
    Exit Sub
          End 
    If
         
    Dim firstCellAddress As String
        firstCellAddress 
    cell.Address
         
    Do
            
    cell.Copy _
                Destination
    :=Sheets("Sheet1").Range("C" Rows.Count).End(xlUp).Offset(10)
            
    Set cell rgSearch.FindNext(cell)
        
    Loop While firstCellAddress <> cell.Address
    End Sub 

  2. #2
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    Here is the file, I need the vba to do for all headers in Sheet1, as it does for column aaa
    If this cannot be done with a loop, what else methods there are ?
    Attached Files Attached Files

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    Hi burvi,

    Something like this?:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    Arkadi, thank you, that is what I need.
    You really are fast.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    You are welcome! If the question is resolved please don't forget to mark the thread as solved? Thanks in advance!

  6. #6
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    Ok, I took at look at the file you emailed, and I think I have some working code:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 03-22-2017 at 03:40 PM. Reason: Added Option Compare Text

  7. #7
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    Yes, I must say this is the solution I was trying to achieve.
    Thank you again.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    You are welcome

    Your email said something about the (x,y) times for yellow cards needing to be separate entries.... did you mean you want each time in the list separately?

  9. #9
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    Yes, all te (x,y) must be separately, of course, with a sign, or something to evidentiate.

  10. #10
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    so paul (32,45) should result in
    paul (32)
    paul (45)
    ?

    or do you simply mean the "," must stay in place? (the code I gave you currently does that)

  11. #11
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    No, paul (32,45) should have result paul (1 dy) - double yellow.

  12. #12
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    so we just make it 1 dy, and forget about the times it happened at?

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    Here is update code, it will replace (32,45) with (1 dy)

    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    No more words... it's perfect.

  15. #15
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,057

    Re: How to loop

    Based on your email I made a change to the code... hope this works well?

    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    10-22-2013
    Location
    Bucharest
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: How to loop

    I tested it and now I noticed the "shortened" did the trick.
    Works perfect, tested and retested.

+ 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] (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
  2. [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
  3. [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
  4. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  5. Loop through multiple files and call macros (but unable to loop)
    By ryanpetersen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2014, 12:04 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

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