Consulting

Results 1 to 5 of 5

Thread: Cells with values

  1. #1
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location

    Cells with values

    I have this code to replace any blank cells in column C with the phrase "in composite"
    [VBA]Sub ZerosAndBlanks()
    ' Fill zero and blank cells
    Dim cll As Range, rng As Range
    Set rng = Range("C1:C" & Cells(Rows.Count, "C").End(xlUp).Row)
    For Each cll In rng
    If cll.Value = "" Then cll.Value = "In composite"
    Next cll

    End Sub[/VBA]

    I would also like to have a code to replace any cell in column C that DOES have something in it with the phrase "out of composite"

    What do I need to put for ??? to trigger all cells that contain something?
    If cll.Value = ???? Then cll.Value = "out of composite"

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [VBA]Sub ZerosAndBlanks()
    ' Fill zero and blank cells
    Dim cll As Range, rng As Range, rngB As Range
    Set rng = Range(Cells(1, 3), Cells(Rows.Count, 3).End(xlUp))
    Set rngB = rng.SpecialCells(xlCellTypeBlanks)
    rng.Value = "out of composite"
    rngB.Value = "in composite"

    End Sub
    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    It says there is an error with this line, error saying no cells were found

    Set rngB = rng.SpecialCells(xlCellTypeBlanks)

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    There must be no blank cells. Can you post sample data?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Mentor
    Joined
    Aug 2011
    Posts
    353
    Location
    thanks for the help, this works great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •