Skip to Content
Menu
This question has been flagged

Example when I export an invoice, first line is complete but succeeding lines for the 2nd and so on invoice items  have  blank  cells  that  indicate  they  are  part  of  the  first  row.    What  I  need  to  fill  those  blank  cells  with  the  values  in  the  first  row  repeating  so  that  there  are  no  blank  rows.    It  facilitates  pivot  processing  using  other  spreadsheet  tools. 

Avatar
Discard
Author

one-value1, one-value2, many-value1-1, many-value1-2
<blank>, <blank> , many-value2-1, many-value2-2
<blank>, <blank> , many-value3-1, many-value3-2

what I want is if possible to have
one-value1, one-value2, many-value1-1, many-value1-2
one-value1, one-value2, many-value2-1, many-value2-2
one-value1, one-value2, many-value3-1, many-value3-2

Did you find any solution here ?

Author Best Answer

I created an excel macro to fill blanks with the last value on top applying it to the selected a range.  Sharing my code to fill down and fill up. 
STEPS:
  (1) select the range you want to process then
  (2) run the macro

Sub FillInBlanksWithLastValue()
oldStatusBar = Application.DisplayStatusBar
Application.DisplayStatusBar = True
prevVal = ""
For Each c In Selection
  Application.StatusBar = "PROCESSING ROW: " & c.Row & " / " & Selection\\.Rows\\.Count
 \\ If\\ Len\\(c\\.Value\\)\\ =\\ 0\\ Then
 \\  \\ c\\.Value\\ =\\ prevVal
 \\ Else
 \\  \\ prevVal\\ =\\ c\\.Value
 \\ End\\ If
Next

\\ \\ \\ \\ Application\\.StatusBar\\ =\\ False
Application\\.DisplayStatusBar\\ =\\ oldStatusBar
End\\ Sub

'\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-\\-

Sub\\ ReverseFillInBlanksWithLastValue\\(\\)
Dim\\ cell\\ As\\ Range
Dim\\ Width\\ As\\ Long
Dim\\ Height\\ As\\ Long

\\ \\ \\ \\ oldStatusBar\\ =\\ Application\\.DisplayStatusBar
Application\\.DisplayStatusBar\\ =\\ True
prevVal\\ =\\ ""
For\\ i\\ =\\ Selection\\.Rows\\.Count\\ To\\ 1\\ Step\\ \\-1
 \\ Application\\.StatusBar\\ =\\ "PROCESSING\\ ROW:\\ "\\ \\&\\ Selection\\.item\\(i\\)\\.Row\\ \\&\\ "\\ /\\ "\\ \\& Selection.Rows.Count

  If Len(Selection.item(i).Value) = 0 Then
    Selection.item(i).Value = prevVal
  Else
    prevVal = Selection.item(i).Value
  End If
Next

Application.StatusBar = False
Application.DisplayStatusBar = oldStatusBar
End Sub


I hope this helps (Just remove the back slashes in the code .. this forum automatically puts them

Avatar
Discard