Solved

Ignore blank cells when using loop to insert formulas

Posted on 2015-02-09
2
59 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
Comment Utility
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
Comment Utility
That worked. Thanks!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
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…

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

18 Experts available now in Live!

Get 1:1 Help Now