VBA Code: Rest Last Cell & Fill All Blanks With -

Nanogirl21

Active Member
Joined
Nov 19, 2013
Messages
330
Office Version
  1. 365
Platform
  1. Windows
[FONT=&quot]Is there a VBA code that I can add to the end of an existing macro that will reset the last cell on worksheet and fill all blanks with a dash (-)? I'd like to do this with every sheet in the workbook. [/FONT]
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You want dashes in ALL the cells...as in all 63,000,000,000 cells in the worksheet?

If so, I think there's a setting to do that without adding anything to your code, but I'll have to wait til tomorrow to look around and find it.
 
Upvote 0
You want dashes in ALL the cells...as in all 63,000,000,000 cells in the worksheet?

If so, I think there's a setting to do that without adding anything to your code, but I'll have to wait til tomorrow to look around and find it.

No, only cells within the active range of data. The range would be identified when the last cell is rest. When the last cell is reset all unused rows and columns will be deleted.

I know you can go to special and select all blanks. Then you can enter - (or whatever you want to fill blanks with) and hit CTRL + ENTER to fill all cells with the value. However, i'm looking for this in a VBA format to add to the end of existing code.
 
Upvote 0
This is going to be an "off-the-cuff" guess until I get to work (where I have excel to test on) tomorrow, but maybe it'll be close. What you can do manually with specialcells, can be done in VBA as well.

Maybe something like this:

Code:
UsedRange.SpecialCells(xlBlankCells).Value = "-"

Again...I'm not terribly familiar with using SpecialCells in VBA, but I know it's possible. Intellisense should show your options after you open the parenthesis after SpecialCells (I hope). If not, and if someone else doesn't come along with an answer, I'll try a couple things out tomorrow and get back to you.
 
Upvote 0
This is going to be an "off-the-cuff" guess until I get to work (where I have excel to test on) tomorrow, but maybe it'll be close. What you can do manually with specialcells, can be done in VBA as well.

Maybe something like this:

Code:
UsedRange.SpecialCells(xlBlankCells).Value = "-"

Again...I'm not terribly familiar with using SpecialCells in VBA, but I know it's possible. Intellisense should show your options after you open the parenthesis after SpecialCells (I hope). If not, and if someone else doesn't come along with an answer, I'll try a couple things out tomorrow and get back to you.

Thank you. I was able to figure it out. I used the below code. Hopefully it can help someone else too!

Code:
    Cells.Select
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Selection.FormulaR1C1 = "-"
 
Upvote 0
FYI you can do that without selecting anything like
Code:
Cells.SpecialCells(xlBlanks).Value = "-"
 
Upvote 0
FYI you can do that without selecting anything like
Code:
Cells.SpecialCells(xlBlanks).Value = "-"

Thank you. Is there a way to apply to all sheets in workbook?

If no blanks found on sheet move to the next sheet.
 
Upvote 0
How about
Code:
Sub FillBlanks()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      On Error Resume Next
      Ws.Cells.SpecialCells(xlBlanks).Value = "-"
      On Error GoTo 0
   Next Ws
End Sub
 
Upvote 0
How about
Code:
Sub FillBlanks()
   Dim Ws As Worksheet
   
   For Each Ws In Worksheets
      On Error Resume Next
      Ws.Cells.SpecialCells(xlBlanks).Value = "-"
      On Error GoTo 0
   Next Ws
End Sub

Perfect
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,334
Members
449,077
Latest member
Jocksteriom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top