Prev Previous Post   Next Post Next
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 96
Default Fill cells

Worked great Chip. Thank you.

"Chip Pearson" wrote:

Try the following code. It works in two ways. You can select any
number of worksheets (hold down the CTRL key and click the worksheet
tabs) and the code will do the fill operation on the selected sheets.
Or, you can code the worksheet names directly in the code.

Sub AAA()
Dim FirstLine As Long
Dim N As Long
Dim LastLine As Long
Dim DataColumn As String
Dim WS As Variant
Dim WSS() As Worksheet

With ActiveWindow.SelectedSheets
If .Count 1 Then
ReDim WSS(1 To .Count)
For N = 1 To .Count
Set WSS(N) = .Item(N)
Next N
Else
ReDim WSS(1 To 4)
Set WSS(1) = Worksheets("Sheet1") '<<< CHANGE AS REQUIRED
Set WSS(2) = Worksheets("Sheet2") '<<< CHANGE AS REQUIRED
Set WSS(3) = Worksheets("Sheet3") '<<< CHANGE AS REQUIRED
Set WSS(4) = Worksheets("Sheet4") '<<< CHANGE AS REQUIRED
End If
For Each WS In WSS
FirstLine = 1 '<<< CHANGE AS REQUIRED
DataColumn = "B" '<<< CHANGE AS REQUIRED
With WS
LastLine = .Cells(.Rows.Count, DataColumn).End(xlUp).Row
For N = FirstLine To LastLine
If .Cells(N, DataColumn).Value = vbNullString Then
.Cells(N, DataColumn).Value = _
.Cells(N - 1, DataColumn)
End If
Next N
End With
Next WS
End With

End Sub

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sun, 8 Mar 2009 10:37:01 -0700, chrisnsmith
wrote:

That worked great Chip, but now I'm sorry to say I need it to work on 4
worksheets. Can you tell me what I need to change?
"Chip Pearson" wrote:

You can use code like

Sub AAA()
Dim FirstLine As Long
Dim N As Long
Dim LastLine As Long
Dim DataColumn As String
Dim WS As Worksheet

FirstLine = 1 '<<< CHANGE AS REQUIRED
DataColumn = "B" '<<< CHANGE AS REQUIRED
Set WS = Worksheets("Sheet1") '<<< CHANGE AS REQUIRED
With WS
LastLine = .Cells(.Rows.Count, DataColumn).End(xlUp).Row
For N = FirstLine To LastLine
If .Cells(N, DataColumn).Value = vbNullString Then
.Cells(N, DataColumn).Value = _
.Cells(N - 1, DataColumn)
End If
Next N
End With

End Sub


Change the lines marked with <<<< to the appropriate values.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sat, 7 Mar 2009 20:31:00 -0800, chrisnsmith
wrote:

Imagine a worksheet that looks something like this:

cell B6 = WH
B40=WK
B55=WN
B73=WU
B88=WZ

The rows between these have no entries in column B. Is there a way to fill
the cells between the WH and WK with WH, and cells between WK and WN with WK
and so on until all cells are filled.




 
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
Fill Cells Based On Cells In Another Sheet [email protected] Excel Worksheet Functions 1 May 31st 07 10:30 PM
Fill cells with color based on criteria in two cells AA Excel Worksheet Functions 2 January 2nd 06 11:29 PM
How do I fill (copy) nonadjacent cells to adjacent cells? BuckyGeorge Excel Discussion (Misc queries) 2 December 22nd 05 04:18 AM
create a fill in template to tab to fill in cells Excel-erator Excel Discussion (Misc queries) 2 July 6th 05 09:57 PM
HOW TO FORMATE CELLS TO COUNT CELLS WITH A FILL COLOR? Moore New Users to Excel 1 June 15th 05 06:41 PM


All times are GMT +1. The time now is 01:16 PM.

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

About Us

"It's about Microsoft Excel"