+ Reply to Thread
Results 1 to 5 of 5

Loop formula on one worksheet until empty cell on another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Loop formula on one worksheet until empty cell on another worksheet

    Hi All,

    I am hoping this is going to be very straight forward for VBA gurus, which I am unfortunately not

    I have 2 worksheets: Sheet1 called “Inspection Report” which contains cells I need to concatenate into Sheet2 called “WW”.
    The number of rows on “Inspection Report” changes with every report so I need to continue the formula in “WW” until an empty cell is found in “Inspection Report” Range E16:E500

    This is the very basic code I have – it covers the formula and insert row but I just can’t seem to get the formula to loop through until an empty cell is found...


    Sub ConcatenateWW()
    '
    'Concatenate Barcode, Location and Code from "Inspection Report"
    'and paste into "WW" Sheet - under Description of Works - starting in cell B8
    'need code to keep adding rows in "WW" and concatenate formula until empty cell
    'in "Inspection Report"
    '
        Sheets("WW").Select
        Range("B8").Select
        ActiveCell.FormulaR1C1 = _
            "=CONCATENATE('Inspection Report'!R[8]C[3],"";   "",'Inspection Report'!R[8]C[6],"";  "",'Inspection Report'!R[8]C[4])"
        Rows("9:9").Select
        Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    
    End Sub
    Would appreciate any help
    Attached Files Attached Files
    Last edited by JBeaucaire; 08-27-2013 at 10:48 AM. Reason: Added CODE tags and corrected title, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Loop formula on one worksheet until empty cell on another worksheet

    Sub ConcatenateWW()
        Dim Description As Variant, _
            Barcode     As Range, _
            Destination As Range
            
        Set Destination = Sheets("WW").Range("B8")
    
        With Sheets("inspection report")
            Set Barcode = .Cells.Find("Barcode").Offset(1, 0)
            
            While Barcode.Value <> ""
                With Barcode
                    Description = Array(.Value, .Offset(0, 1).Value, .Offset(0, 3).Value)
                    Description = Join(Description, ", ")
                End With
                Destination.Value = Description
                Destination.Offset(1, 0).EntireRow.Insert shift:=xlDown
                Set Barcode = Barcode.Offset(1, 0)
                Set Destination = Destination.Offset(1, 0)
                
            Wend
        End With
    End Sub
    Attached Files Attached Files
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    09-28-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Loop formula on one worksheet until empty cell on another worksheet

    Thanks for your reply protonLeah, unfortunately that code didn't seem to work for me ? Sorry it's hard to articulate exactly what I'm after, I need to concatenate each separate row of Barcode, Location and Code from "Inspection Report" from the range E16:E500 and enter the concatenated data on the "WW" worksheet starting at B8 and inserting enough rows each time so as not to overwrite the "WW" Form but cover all "Inspection Report" rows (the number of rows will constantly change with each file).

    Thanks in advance, your help is appreciated

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Loop formula on one worksheet until empty cell on another worksheet

    Evidently, you have the word "barcode" somewhere above row 16 so replace the line:
    Set Barcode = .Cells.Find("Barcode").Offset(1, 0)

    with
            Set Barcode = .Range("E16")
    The While loop will exit when an empty cell is found in column E
    Last edited by protonLeah; 08-27-2013 at 10:33 PM.

  5. #5
    Registered User
    Join Date
    09-28-2012
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Loop formula on one worksheet until empty cell on another worksheet

    Thanks so much protonLeah, that's perfect

+ 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] If cell is not empty, copy entire row to new worksheet
    By mattman123 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 07-30-2013, 03:33 PM
  2. worksheet object as string - loop statement in worksheet index
    By ag273n in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2013, 12:27 PM
  3. [SOLVED] Trouble finding first empty cell on different worksheet
    By oscari in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-26-2012, 05:14 AM
  4. Copy Range from Worksheet 2, Paste to Next Empty Row Worksheet 1
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-21-2010, 04:07 PM
  5. Empty cell deletion at bottom of worksheet
    By DarCady in forum Excel General
    Replies: 2
    Last Post: 09-24-2009, 03:25 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