Solved

Ignore blank cells when using loop to insert formulas

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
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…

691 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