Consulting

Results 1 to 6 of 6

Thread: Solved: Fill Down to cells that appear blank

  1. #1
    VBAX Regular
    Joined
    Nov 2007
    Posts
    11
    Location

    Solved: Fill Down to cells that appear blank

    Hello,

    My problem is that I am trying to use a fill down macro and for one column, where I had previously used a formula to populate it, the values are not being properly filled down.

    I am using the following to fill down to blank cells:

    Columns("A:C").Select
    Dim oRng As Range
    Set oRng = Selection
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.Font.Bold = False
    Selection.FormulaR1C1 = "=R[-1]C"
    oRng.Copy
    oRng.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False

    This works fine, except for column A. In column A, I had previously used a formula to fill the cells. I then deleted all but every ten or so cells. I then pasted special so that it appears as if all but every tenth cell or so is populated and the others are blank, with no formulas:

    Range("A1").Select
    ActiveCell.FormulaR1C1 = _
    "=IF(OR(RC[1]=""A"",RC[1]=""B""),RC[2],""XXX"")"
    Range("A1").Select
    Selection.AutoFill Destination:=Range("A1:A269"), Type:=xlFillDefault
    Range("A1:A269").Select
    Columns("A:A").Select
    Selection.Replace What:="XXX", Replacement:="", LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False

    Columns("A:A").Select
    Selection.Copy
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    The problem is that it looks like Excel is not reading those cells as blank. They are not being filled in.

    Thank you in advance for your help.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I am struggling to see what this codes does/is supposed to do?

    Can you give an English description, and post a workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Nov 2007
    Posts
    11
    Location
    I am attaching a sample workbook.

    My main objective is to get each row to have a cell telling which "heading" it is tied to. I am doing this by:

    1. Insert Column A.
    2. In column A, I am providing a formula that says: If Column B has "A" or "B" in it, then copy "HeadingX" to column A.
    3. Copy and paste the values in column A (I don't know if this is necessary, but I thought it might help Excel to recognize the blank cells as actually empty).
    4. Fill down all of the empty cells (between populated cells) in Columns A through C.

    In the 4th step, the empty cells in column A are not being filled in.

    Thanks!

  4. #4
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Can you post the same workbook but with a sheet with how it looks before the macro is run and a sheet with how you would like it to look? A befor and after if you like.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  5. #5
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Like this?

    [VBA]Sub Filler()
    Dim MyRange As Range, rCell As Range
    Dim HRow As Integer

    Range("A:A").Insert

    Set MyRange = Range("B1:B500")


    For Each rCell In MyRange.Cells


    'to define header row
    If rCell.Value = "A" Then
    HRow = rCell.Row
    Else
    If rCell.Value = "B" Then HRow = rCell.Row
    End If

    If rCell.Offset(, 3).Value = "" Then
    rCell.Value = ""
    Else
    rCell.Offset(, -1).Value = Range("C" & HRow).Value
    End If


    Next rCell[/VBA]
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  6. #6
    VBAX Regular
    Joined
    Nov 2007
    Posts
    11
    Location
    That works! And much more efficient! I still need to fill down the blank cells in columns B and C, but I have working code for that. Thanks!

Posting Permissions

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