Solved

Search a range of data in Excel programmatically

Posted on 2014-02-04
2
158 Views
Last Modified: 2014-02-19
I have an Excel file that contains (for the most part) numeric data in columns B through F, rows 2 through 100 (row 1 contains headers). Some cells in that range are blank. I have already run a TRIM routine on the worksheet as well having manually deleted alls rows and columns outside of the used range. I need a routine that will search all cells in the used range and put a value of 0 (zero) in all blank cells in the range. Ideally, I need a routine that could be used for worksheets that have a few more columns and more rows. It just so happens that the file I am currently dealing with only has data in the columns and rows specified above. For example, the next file I have to work with may have data in columns B through Z and rows 2 through 500. Thank you.
0
Comment
Question by:dbfromnewjersey
2 Comments
 
LVL 18

Assisted Solution

by:Steven Harris
Steven Harris earned 250 total points
Comment Utility
Insert the following code:

Sub FillEmptyBlankCellWithValue()
Dim cell As Range
Dim InputValue As String
On Error Resume Next
InputValue = "0"
    For Each cell In Selection
        If IsEmpty(cell) Then
            cell.Value = InputValue
        End If
    Next
End Sub

Open in new window


Select your range, then use Alt+F8 to bring up the Macro Selector and run the macro.

Example file attached.
FillBlank.xlsm
0
 
LVL 31

Accepted Solution

by:
Rob Henson earned 250 total points
Comment Utility
Rather than selecting the area and then checking each and every cell.

Press F5, select Special, select Blanks and click OK. That then only selects blanks in the current used region.

The macro can then simply be:

For Each cell In Selection
        cell.Value = 0
Next cell

Alternatively without need for VBA, put a zero in the first blank cell and then copy it to the clipboard with Ctrl + C. Then use the F5, Special, Blanks selection and then Paste Special > Values.

Thanks
Rob H
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now