MACRO TO AUTOFILL W/ SPECIAL CHARACTER TILL LAST ROW OF DATA (not fill from text above)

JuicyMusic

Board Regular
Joined
Jun 13, 2020
Messages
210
Office Version
  1. 365
Platform
  1. Windows
Good morning,
I have a PDF that I'm converting to Excel. All the data gets populated in column A. The last row of data varies.

I usually use the Ctrl-G autofill formula to copy the data from the row above. I need a different autofill formula. I would prefer a Macro to run on whatever column I am highlighting.

Is there a VBA to insert whatever type of text I'd like in the blank cells....till the last row of data? For example, I'd like two asterisks (**) to be filled in every blank cell in column A (or whatever column I have made active.

Thank you so much,
Juicy
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Select the desired range and try this macro:
VBA Code:
Sub FillBlankCells()
    Application.ScreenUpdating = False
    Selection.Replace "", "**"
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Hi,
As an example ... just double-click
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim st As String, lastr As Long
st = "**"
lastr = Cells(Rows.Count, "A").End(xlUp).Row
' For any Column ...
Range(Cells(1, Target.Column), Cells(lastr, Target.Column)).SpecialCells(xlCellTypeBlanks).Value = st
Cancel = True
End Sub
 
Last edited:
Upvote 0
Another option
VBA Code:
Sub juicymusic()
   On Error Resume Next
   Selection.SpecialCells(xlBlanks).Value = "**"
   On Error GoTo 0
End Sub
 
Upvote 0
Solution
Select the desired range and try this macro:
VBA Code:
Sub FillBlankCells()
    Application.ScreenUpdating = False
    Selection.Replace "", "**"
    Application.ScreenUpdating = True
End Sub
IT worked perfectly for me. I see the two screen updating lines so it doesn't flash while the code is running. Could you let me know why there are two lines like that?
Just wanting to learn even though it worked perfectly.
 
Upvote 0
Another option
VBA Code:
Sub juicymusic()
   On Error Resume Next
   Selection.SpecialCells(xlBlanks).Value = "**"
   On Error GoTo 0
End Sub
Fluff, yours worked as well. I added them both to a module. I see what you did there. Shortened the code and no line to stop flashing.
I really wanted this code because the PDF to Excel conversion results in so many blank rows between pages that I couldn't get any data back when I set a filter on the header row. I love it!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Hi,
As an example ... just double-click
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim st As String, lastr As Long
st = "**"
lastr = Cells(Rows.Count, "A").End(xlUp).Row
' For any Column ...
Range(Cells(1, Target.Column), Cells(lastr, Target.Column)).SpecialCells(xlCellTypeBlanks).Value = st
Cancel = True
End Sub
Hi, where should I click?...on the first blank cell?
 
Upvote 0
You can double-click on any cell in any column ...
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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