Solved

Ignore blank cells when using loop to insert formulas

Posted on 2015-02-09
2
63 Views
Last Modified: 2016-02-10
I'm trying to parse the date and time out of a date-time field.  I know how to loop through my data using VBA to insert a formula in a new column. I want to make sure the loop ignores cells that are blank. Otherwise I end up with date 1/1/1900 where there should be nothing.

Sub GetTotal()
Dim lstrow As Integer
Dim i As Integer

Application.ScreenUpdating = False

        lstrow = Cells(Rows.Count, 1).End(xlUp).Row

        Range("X3:X" & lstrow).FormulaR1C1 = "=INT(RC[-1])"

Application.ScreenUpdating = True

End Sub

Open in new window

0
Comment
Question by:zinoviia660
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 40599240
How about modifying the formula to "ignore" blanks....

    Range("X3:X" & lstrow).FormulaR1C1 = "=IF(RC[-1]="""", """", INT(RC[-1]))"

Wayne
0
 

Author Comment

by:zinoviia660
ID: 40599544
That worked. Thanks!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

820 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