View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
JenIT JenIT is offline
external usenet poster
 
Posts: 25
Default Need macro to check if cell is not blank & previous cell is blank, copy information from row above & paste

Hi Dave:

Thanks for the prompt response. I do need code as I need this to work
all within a macro. I followed the link and your code is on track but
no matter if I use the
col = activecell.column
'or
'col = .range("A2:E3000").column - the lenth of my sheet is a
variable
It always only replaces in col A and then when it gets to the bottom
of .value = .value it breaks.

I am fairly new to VB so I could use any guidance you have. I need
to replace my blanks in A:E however col F must remain in tact as
that is sometimes a variable. - Below is the code from the link that
I used

Sub FillColBlanks()
'by Dave Peterson 2004-01-06
'fill blank cells in column with value above
Dim wks As Worksheet
Dim rng As Range
Dim LastRow As Long
Dim col As Long

Set wks = ActiveSheet
With wks
col = activecell.column
'or
'col = .range("b1").column

Set rng = .UsedRange 'try to reset the lastcell
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
Set rng = Nothing
On Error Resume Next
Set rng = .Range(.Cells(2, col), .Cells(LastRow, col)) _
.Cells.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0

If rng Is Nothing Then
MsgBox "No blanks found"
Exit Sub
Else
rng.FormulaR1C1 = "=R[-1]C"
End If

'replace formulas with values
With .Cells(1, col).EntireColumn
.Value = .Value
End With

End With

End Sub