Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fill empty cells in a range using the used cell

I have a macro that Color codes all the empty cells in the Range and enters
the legend Missing! to show what attributes need to be entered.

Sub FillEmptyCells()
WCount = Worksheets.Count
For i = 1 To WCount
If Worksheets(WCount - i + 1).Visible Then
Worksheets(WCount - i + 1).Select
RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
For j = 1 To RCount
For k = 1 To CCount
If IsEmpty(Worksheets(WCount - i + 1).Cells(j, k)) Then
Worksheets(WCount - i + 1).Cells(j, k) = "Missing!"
Worksheets(WCount - i + 1).Cells(j, k).Interior.ColorIndex = 35
Worksheets(WCount - i + 1).Cells(j, k).Font.Bold = True
End If
Next k
Next j
End If
Next i

End Sub

The idea is that my spreadhsheets will be shrinking over the time because
less number of cells will have missing attributes. The above macro worked
well for a while until my spreadsheets started shrinking and some of the last
rows were all filled with Missing! and color coded, I think it was because
somehow Excel detected them as "active" although they have no values. I read
and article about the "Last Cell" only being reset when you save and the user
who looks at the excel file can't save it (I made that intentionally) so I
guess my problem has to do with that.

On other website I found the sintax to select the Last Used Cell in a row or
column

Sub LastCellInRow()
Range("IV1").End(xlToLeft).Select
End Sub

Sub LastCellInColumn()
Range("A65536").End(xlUp).Select
End Sub

But I don't know how to include this as the range on the previous macro, in
short, I need my range to be from A2 to the last used Column,Row. I hope it
is not to confusing and I appreciate any help.

Thanks
Bruno

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Fill empty cells in a range using the used cell

The following uses the usedrange which is from the first cell used to the
last cell used. It may be ok and easier to follow.

Sub FillEmptyCells()
Dim ws As Worksheet
Dim r As Range

For Each ws In ActiveWorkbook.Worksheets

If ws.Visible Then
If ws.UsedRange.Address < "$A$1" Then
For Each r In ws.UsedRange
If IsEmpty(r) Then
r.Value = "Missing!"
r.Interior.ColorIndex = 35
r.Font.Bold = True
End If
Next r
End If
End If
Next ws
Set r = Nothing
Set ws = Nothing
End Sub



--
Hope this helps
Martin Fishlock
Please do not forget to rate this reply.


"bdmsfan" wrote:

I have a macro that Color codes all the empty cells in the Range and enters
the legend Missing! to show what attributes need to be entered.

Sub FillEmptyCells()
WCount = Worksheets.Count
For i = 1 To WCount
If Worksheets(WCount - i + 1).Visible Then
Worksheets(WCount - i + 1).Select
RCount = ActiveCell.SpecialCells(xlLastCell).Row
CCount = ActiveCell.SpecialCells(xlLastCell).Column
For j = 1 To RCount
For k = 1 To CCount
If IsEmpty(Worksheets(WCount - i + 1).Cells(j, k)) Then
Worksheets(WCount - i + 1).Cells(j, k) = "Missing!"
Worksheets(WCount - i + 1).Cells(j, k).Interior.ColorIndex = 35
Worksheets(WCount - i + 1).Cells(j, k).Font.Bold = True
End If
Next k
Next j
End If
Next i

End Sub

The idea is that my spreadhsheets will be shrinking over the time because
less number of cells will have missing attributes. The above macro worked
well for a while until my spreadsheets started shrinking and some of the last
rows were all filled with Missing! and color coded, I think it was because
somehow Excel detected them as "active" although they have no values. I read
and article about the "Last Cell" only being reset when you save and the user
who looks at the excel file can't save it (I made that intentionally) so I
guess my problem has to do with that.

On other website I found the sintax to select the Last Used Cell in a row or
column

Sub LastCellInRow()
Range("IV1").End(xlToLeft).Select
End Sub

Sub LastCellInColumn()
Range("A65536").End(xlUp).Select
End Sub

But I don't know how to include this as the range on the previous macro, in
short, I need my range to be from A2 to the last used Column,Row. I hope it
is not to confusing and I appreciate any help.

Thanks
Bruno

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
Paste to next empty cell in named range of cells Sully Excel Discussion (Misc queries) 3 March 4th 10 05:23 PM
Find empty cells, fill with text from cell above Marketer Excel Worksheet Functions 1 August 27th 07 10:35 PM
Macro Request: Fill in empty cells with previous Filled cell in column Artis Excel Worksheet Functions 2 June 25th 07 08:30 PM
Fill empty cells [email protected] Excel Programming 2 May 23rd 06 04:44 PM
Fill empty cells Thiem[_2_] Excel Programming 1 January 9th 06 11:03 AM


All times are GMT +1. The time now is 09:10 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"