Solved

Ignore blank cells when using loop to insert formulas

Posted on 2015-02-09
2
61 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

770 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