Results 1 to 5 of 5

Thread: VBA fill blank cells with value above

  1. #1
    Seeker ProbioT's Avatar
    Join Date
    Jan 2019
    Posts
    8
    Articles
    0
    Excel Version
    2007

    Post VBA fill blank cells with value above



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi all,
    I have created a user form, which works fine if all boxes are populated.
    My intention is not to fill out all boxes each time, just changed data will be transferred to the spread sheet.

    In that case it will give me blank cells with no data. I'd like to populate blank cells (with no change in the row) with values from cells above.

    Can someone help, please?
    Thanks.
    Attached Files Attached Files

  2. #2
    Magician NoS's Avatar
    Join Date
    Jan 2013
    Location
    British Columbia
    Posts
    782
    Articles
    0
    Excel Version
    Excel 2010
    Try adding this to the end of your submitComandButton_Click()
    Code:
        'Fill blanks from above
        For col = 3 To 11
            If ThisWorkbook.Worksheets("Sheet1").Cells(lastrow + 1, col) = "" Then
                ThisWorkbook.Worksheets("Sheet1").Cells(lastrow + 1, col) = ThisWorkbook.Worksheets("Sheet1").Cells(lastrow, col)
            End If
        Next col

  3. #3
    Seeker ProbioT's Avatar
    Join Date
    Jan 2019
    Posts
    8
    Articles
    0
    Excel Version
    2007
    Omg... it works like a charm. Thank you so much. I spent hours of researching it on the internet without any success.
    Great work!

  4. #4
    Magician NoS's Avatar
    Join Date
    Jan 2013
    Location
    British Columbia
    Posts
    782
    Articles
    0
    Excel Version
    Excel 2010
    You're welcome, and thanks for the feed back.

  5. #5
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,650
    Articles
    0
    Excel Version
    365
    Old thread, I know; The whole submit macro can be condensed:
    Code:
    Private Sub submitCommandButton_Click()
    With ThisWorkbook.Worksheets("Sheet1")
      lastrow = .Cells(.Rows.Count, 1).End(xlUp).Row
      With .Range(.Cells(lastrow + 1, 1), Cells(lastrow + 1, 13))
        .Value = Array(dateTextBox.Value, modelComboBox.Value, zone1_ComboBox.Value, zone2_ComboBox.Value, zone3_ComboBox.Value, zone4_ComboBox.Value, levelComboBox.Value, northComboBox.Value, westComboBox.Value, eastComboBox.Value, southComboBox.Value, materialComboBox.Value, commentTextBox.Value)
        For Each cll In .Cells
          If Len(cll.Value) = 0 Then cll.Value = cll.Offset(-1).Value
        Next cll
      End With
    End With
    End Sub

Posting Permissions

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