+ Reply to Thread
Results 1 to 2 of 2

IF loop for single rows and print values in one cell?

Hybrid View

Jimbo8678 IF loop for single rows and... 11-03-2020, 11:25 AM
nigelog Re: IF loop for single rows... 11-03-2020, 11:45 AM
  1. #1
    Registered User
    Join Date
    11-03-2020
    Location
    Manchester, England
    MS-Off Ver
    2016
    Posts
    1

    Smile IF loop for single rows and print values in one cell?

    Hi,

    First time posting here so hopefully I explain this well enough...

    I have columns of data, some of which have no data in, some of which have a number such as 108-88-3.

    What I would like to do is use the IF function, but then print the values of the cells in a single cell.

    Sum Excel Query.PNG

    Formula in Sum column is - =IF(E13<>0,""&E13&";","")&IF(F13<>0,""&F13&";","")&IF(G13<>0,""&G13&";","")&IF(H13<>0,""&H13&";","")

    The formula above works in the way I want, however I have 500 column to do this for and so need a way to get excel to do the above for me!

    Please ask me any questions if I haven't been clear!

  2. #2
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,293

    Re: IF loop for single rows and print values in one cell?

    For that layout, returning from array rather than formula
    Sub test()
    Dim a, i, ii, str As String
    a = [b1].CurrentRegion.Offset(1, 0)
        For i = LBound(a, 1) To UBound(a, 1)
         For ii = LBound(a, 2) To UBound(a, 2)
            If a(i, ii) <> "" Then str = str & "," & a(i, ii)
         Next ii
         Cells(i + 1, 1).Value = str: str = ""
        Next i
    End Sub
    Right click on sheet tab - "View code" - paste above code and press F5
    Last edited by nigelog; 11-03-2020 at 11:55 AM.

+ 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. VBA Loop to change values to each cell of a named range and print
    By wateriswad in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2018, 10:14 AM
  2. Help for print in single click for use next loop in VBA
    By sam51285 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2017, 12:46 AM
  3. [SOLVED] How to delete rows by especifying the values of a single cell?
    By Urlant in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 09-22-2017, 12:17 AM
  4. [SOLVED] VBA Split Cell Contents to New Rows & Copy Cells containing single values to the new rows
    By jaimelwilson in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-14-2017, 05:30 PM
  5. Print sheet with changed cell values in single command
    By matvmat in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-24-2013, 03:07 AM
  6. Need help on the rows & column values to be merged to a single cell.
    By phanindrachitta in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-20-2012, 05:15 PM
  7. VBA. identify unique values, loop them, filter them in, set print area & print it
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-09-2012, 09:56 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