Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Macro for Fill Blank Cells Macro

Hello,

I searched the macro for fill blank cells . May I know how to modified the
following macro, therefore, it can apply on column B, C and E? Thanks


Sub FillColBlanks()
'by Dave Peterson 2004-01-06
'fill blank cells in column with value above
'http://www.contextures.com/xlDataEntry02.html
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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Macro for Fill Blank Cells Macro

I searched the macro for fill blank cells . May I know how to
modified the following macro, therefore, it can apply on
column B, C and E? Thanks

<<<code snipped


Does this code do what you want...

Sub FillColBlanks()
Dim Col As Variant, Data As Range, A As Range
For Each Col In Array("B", "C", "E")
Set Data = Range(Cells(1, Col), Cells(Rows.Count, Col).End(xlUp))
For Each A In Data.SpecialCells(xlCellTypeBlanks).Areas
A.Value = A(1).Offset(-1).Value
Next
Next
End Sub

Rick Rothstein (MVP - Excel)
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Macro for Fill Blank Cells Macro

Sorry, I forgot to include the error trapping. Use this code instead...

Sub FillColBlanks()
Dim Col As Variant, Data As Range, A As Range
On Error GoTo NoCellsFound
For Each Col In Array("B", "C", "E")
Set Data = Range(Cells(1, Col), Cells(Rows.Count, Col).End(xlUp))
For Each A In Data.SpecialCells(xlCellTypeBlanks).Areas
A.Value = A(1).Offset(-1).Value
Next
Next
NoCellsFound:
End Sub

Rick Rothstein (MVP - Excel)
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to fill blank cells Sunny Links and Linking in Excel 1 March 24th 06 09:09 AM
Macro to transpose data to fill blank cells in table nospaminlich Excel Programming 5 October 29th 05 10:23 AM
Use Autofill in a macro to fill blank cells until next text - goldyjk Excel Programming 1 June 14th 05 06:40 PM
Use Autofill in a macro to fill blank cells until next text - Bernie Deitrick Excel Programming 0 February 18th 05 06:45 PM
A macro to fill in the blank cells jer101[_3_] Excel Programming 7 June 18th 04 03:13 AM


All times are GMT +1. The time now is 07:11 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"