?
Solved

Ignore blank cells when using loop to insert formulas

Posted on 2015-02-09
2
Medium Priority
?
71 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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