+ Reply to Thread
Results 1 to 6 of 6

If is empty auto fill condition- loop through for first blank row/cell

Hybrid View

  1. #1
    Registered User
    Join Date
    10-20-2017
    Location
    Seattle, WA USA
    MS-Off Ver
    MS Office 2010 & Windows 7
    Posts
    20

    If is empty auto fill condition- loop through for first blank row/cell

    the below sub four is executing properly with the exception of this line- the conditions have not changed. The rest of the code does what I need it to, but when I run it the case2 ""Unbilled Vendor Invoices Pending Client Payment" does nothing. 
    
     CODE:
        Dim cnter As Integer
    
        lastRow = Cells(Rows.Count, 1).End(xlUp).Row
        cnter = 0
    
        For i = 5 To lastRow
            If IsEmpty(Cells(i, 1)) Then
                Select Case cnter
                    Case 0: Cells(i, 1).Value = "Vendor Invoices to Pay"
                    Case 0: Cells(i, 1).Font.Bold = True
                    Case 1: Cells(i, 1).Value = "Billed Vendor Invoices Pending Client Payment"
                    Case 1: Cells(i, 1).Font.Bold = True
                BAD CODE ===>    Case 2: Cells(i, 1).Value = "Unbilled Vendor Invoices Pending Client Payment"
                    Case 2: Cells(i, 1).Font.Bold = True
                    Case Else: Cells(i, 1).Value = ""
                End Select
                cnter = cnter + 1
            End If
        Next i

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: If is empty auto fill condition- loop through for first blank row/cell

    Hi Steven

    Can't say what is wrong with this code at the first glance as the other works according to you. Could it be a spelling mistake in the string or an extra space in worksheet cells?

    By the way if this code is supposed to work on the same file as I made a macro for and if you only wish to set font bold that could be included in my previous code i.e:

    Cells(i, 1).EntireRow.Interior.Color = 10092543
    
    Cells(i, 1).Font.Bold = True
    Perhaps you could upload a small file sample after removing sensitive information showing how the data look like and how you would like it to look after the change.

    Alf

  3. #3
    Registered User
    Join Date
    10-20-2017
    Location
    Seattle, WA USA
    MS-Off Ver
    MS Office 2010 & Windows 7
    Posts
    20

    Re: If is empty auto fill condition- loop through for first blank row/cell

    Hi Alf, 
    
    this one I just want to have insert this text at the first break. 
    
    BAD CODE ===>    Case 2: Cells(i, 1).Value = "Unbilled Vendor Invoices Pending Client Payment"
    
    what's odd is that the code above it works
    Case 1: Cells(i, 1).Value = "Billed Vendor Invoices Pending Client Payment"
    Case 0: Cells(i, 1).Value = "Vendor Invoices to Pay"

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: If is empty auto fill condition- loop through for first blank row/cell

    Hi Steven

    I did a bit of testing with your macro an I don't have any problem with filling the empty cells with the proper values but on the other hand I tested only a range with 16 values with three empty cells in that range.

    What i did have problem with was the "Font.Bold" setting that I could not get to work so I had to change code a bit. As I use "Option Explicit" when writing macros I had to declare all variables.

    Option Explicit
    
     Sub testCase()
     Dim cnter As Integer
     Dim lastRow As Integer
     Dim i As Integer
    
        lastRow = Cells(Rows.Count, 1).End(xlUp).Row
        cnter = 0
    
        For i = 2 To lastRow
            If IsEmpty(Cells(i, 1)) Then
                Select Case cnter
                    Case 0: Cells(i, 1).Value = "Vendor Invoices to Pay"
                    Cells(i, 1).Font.Bold = True
                    Case 1: Cells(i, 1).Value = "Billed Vendor Invoices Pending Client Payment"
                    Cells(i, 1).Font.Bold = True
                    Case 2: Cells(i, 1).Value = "Unbilled Vendor Invoices Pending Client Payment"
                    Cells(i, 1).Font.Bold = True
                    Case Else: Cells(i, 1).Value = ""
                End Select
                cnter = cnter + 1
            End If
        Next i
     End Sub
    Alf

  5. #5
    Registered User
    Join Date
    10-20-2017
    Location
    Seattle, WA USA
    MS-Off Ver
    MS Office 2010 & Windows 7
    Posts
    20

    Re: If is empty auto fill condition- loop through for first blank row/cell

    interesting, I took out the Case for the bold.font and just left it in the .value. 
    
    it still did not generate the Case 2: Cells(i, 1).Value = "Unbilled Vendor Invoices Pending Client Payment"
    
    but still code worked for 
    Case 1: Cells(i, 1).Value = "Billed Vendor Invoices Pending Client Payment"
    Case 0: Cells(i, 1).Value = "Vendor Invoices to Pay"
    
    This is odd that it is calling same logic and one code produces but the other does not. I am relatively new to coding so maybe I will see this again sometime.

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,784

    Re: If is empty auto fill condition- loop through for first blank row/cell

    This is rather strange. I've no problem with your code as far as I understand what you wish to do. I've uploaded a small file created in Excel 2010.

    Since your macro specifies three cases only the three first empty cells are filled with text set to bold. The forth empty cell is not modified by macro.

    Test and see if this macro works in your excel environment.

    Alf
    Attached Files Attached Files

+ 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. How To Loop a copy range macro until lookup cell is blank/empty
    By iggypop in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-02-2017, 09:44 AM
  2. auto fill not working for data above empty cell
    By mrl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-28-2017, 11:11 AM
  3. [SOLVED] Toggle fill Color in cell based on condition of cell--blank or text added.
    By moosetales in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2014, 08:39 PM
  4. transpose loop with "empty cell" condition
    By ana_cociorva in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2011, 04:24 PM
  5. Auto fill & auto blank cell
    By sushant.gore in forum Excel General
    Replies: 1
    Last Post: 10-07-2010, 01:06 PM
  6. fill empty with two condition
    By johncena in forum Excel General
    Replies: 2
    Last Post: 02-22-2010, 04:17 AM
  7. Auto fill blank cells with data in a cell above
    By StudentMod in forum Excel General
    Replies: 4
    Last Post: 05-09-2008, 04:37 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