+ Reply to Thread
Results 1 to 6 of 6

Thread: Create list of blank fields

  1. #1
    Registered User
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    58

    Create list of blank fields

    Hi,
    See attached mock-up.
    I have a database style list that contain blanks in some fields
    I wish to extract the ID and the field name (top row of list) to create a list of those blanks by ID, e.g.

    ID Field
    1 Field 3
    1 Field 5
    3 Field 2
    3 Field 7

    My list is over 1000 rows long and I just want to be able to quickly identify the blanks by ID

    Thanks
    Attached Files Attached Files
    Last edited by reddwarf; 01-24-2012 at 06:02 AM. Reason: typo

  2. #2
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Create list of blank fields

    As per your example:

    Sub getBlanks(TopLeft As Range, listRng As Range)
    'TopLeft is the top left cell of the table
    'Listrng is the cell where the list should start
    
    
    Dim ocell As Range
    Dim i As Integer
    
    For Each ocell In TopLeft.CurrentRegion.SpecialCells(xlCellTypeBlanks)
        listRng.Offset(i, 0).Value = ocell.Row - TopLeft.Row
        listRng.Offset(i, 1).Value = "Field " & ocell.Column - TopLeft.Column
        i = i + 1
    Next ocell
    
    End Sub
    Sub test()
        getBlanks Sheet1.Range("C3"), Sheet1.Range("C30")
    End Sub
    Last edited by Kyle123; 01-24-2012 at 06:15 AM.
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  3. #3
    Registered User
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Create list of blank fields

    Wow! That is excellent - worked 1st time.
    Thanks very much

  4. #4
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Create list of blank fields

    or:
    Sub snb()
      j = 0
      ReDim sn(Cells(3, 3).CurrentRegion.SpecialCells(4).Count - 1, 1)
    
      For Each cl In Cells(3, 3).CurrentRegion.SpecialCells(4)
        sn(j, 0) = cl.Offset(, 3 - cl.Column)
        sn(j, 1) = cl.Offset(3 - cl.Row)
        j = j + 1
      Next
        
      Cells(18, 1).Resize(UBound(sn) + 1, 2) = sn
    End Sub
    NB. the main difference is that there will be written only once into the worksheet.



  5. #5
    Valued Forum Contributor Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds/Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    1,031

    Re: Create list of blank fields

    or even better, a combination:
    Sub getBlanks(TopLeft As Range, listRng As Range)
    'TopLeft is the top left cell of the table
    'Listrng is the cell where the list should start
    
    Dim ocell As Range
    Dim i As Integer
    Dim arr
    
    ReDim arr(TopLeft.CurrentRegion.SpecialCells(xlCellTypeBlanks).Count - 1, 1)
    For Each ocell In TopLeft.CurrentRegion.SpecialCells(xlCellTypeBlanks)
        arr(i, 0) = ocell.Row - TopLeft.Row
        arr(i, 1) = "Field " & ocell.Column - TopLeft.Column
        i = i + 1
    Next ocell
    
    listRng.Resize(UBound(arr) + 1, 2).Value = arr
    
    
    End Sub
    Click the * below to say thanks

    Girls sleep with guys who use photoshop, but marry the ones who work with Excel

    Corduroy
    pillows: They're making headlines!

    Did you mean: recursion
    http://www.google.com/search?hl=en&q=recursion

  6. #6
    Registered User
    Join Date
    07-06-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    58

    Re: Create list of blank fields

    Thank you Kyle & snb.

    I'm glad I checked back - I needed the code to return the field name rather than Field 1, Field 2, which I used as a mockup
    Just ran snb's code and it works really well. Great time saver - thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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.2.0