VBA code for an error

Xrull

Board Regular
Joined
Dec 26, 2008
Messages
73
Good Day to you all,
I'm trying to write a VBA code to place the value of these formulas in the cells.

Code:
=IF(ISERROR(IF(D3="","",I3-F3)),"Re-check",(IF(D3="","",I3-F3)))
or
Code:
=IF(ISERROR(IF(D3<>"",I3-F3,"")),"Re-check",(IF(D3<>"",I3-F3,"")))

These formulas are subtracting dates.
I need it to run the length of Column N.
I tried to write a code, I'm unable to overcome the error a text is placed in the a cell in column L or column I in the but I'm afraid it is not making any sense to me.
Please help,
Xrull
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Your formula does not make sense to me...

What does IsError function evaluate in your formula?

IsError("")
IsError(Number)

????

IsError function evaluates if the argument is Error or not.
 
Upvote 0
Seiya,
Sometimes I data that is not a date format (when I'm tired or not being careful), and I need to see where there is an error to go back and put the correct date in there.
When I tried writing a code, similar to the one you gave me earlier today, it just doesn't work.
Code:
Sub Macro15() 'Invoice date to post date
 With Sheets("Entry")
      With .Range("M3:M" & .Range("D" & Rows.Count).End(xlUp).Row)
          .Formula = "=IF(L3" <> ""","""",L3 - I3)"
         .Value = .Value
      End With
  End With
End Sub
It doesn't subtract.
Thanks,
Xrull
 
Upvote 0
Seiya,
Sometimes I data that is not a date format (when I'm tired or not being careful), and I need to see where there is an error to go back and put the correct date in there.
When I tried writing a code, similar to the one you gave me earlier today, it just doesn't work.
Code:
Sub Macro15() 'Invoice date to post date
 With Sheets("Entry")
      With .Range("M3:M" & .Range("D" & Rows.Count).End(xlUp).Row)
          .Formula = "=IF(L3" <> ""","""",L3 - I3)"
         .Value = .Value
      End With
  End With
End Sub
It doesn't subtract.
Thanks,
Xrull
You are not explaining your porblem.

What is the correct date and where do you mean there ?
 
Upvote 0
Seiya,

I am subtracting 2 dates, the dates are in columns L and I.

The code I wrote returns "true" in the column a cells instead of giving me the amount of days between the dates.

I want a code than can subtract the dates, or return an error message in the cells of column M if I put date that is not in the correct format (1/1//2009) or any other entry that is not a date entry in a cell in either column L or column I.

Thanks again,
Xrul
 
Upvote 0
I agree with Seiya about not making sense, but came up with this from a bit of guesswork.

Assumes dates are in columns I and L, earlier date in I
Assumes that this formula is going in column M
Assumes that if column D is blank M is to be left blank
Assumes that you want the result in the cell, not the formula.

Code:
Sub Macro15() 'Invoice date to post date
 With Sheets("Entry")
      For a = 3 To Range("D" & Rows.Count).End(xlUp).Row
      Range("M" & a) = "=IF(D" & a & "="""","""",IFERROR(L" & a & "-I" & a & ",""Re-check""))"
      Range("M" & a) = Range("M" & a).Value
      Next
      End With
 
End Sub
 
Last edited:
Upvote 0
jasonb,
The formula you gave me is returning "#Name?"

Column D holds the names of persons, Column I is for the entry date, and Column L is for the end date. I need to find the amount of days between the start and and end date in cells in Column M. In the event I put something that is not a date in Column I or L I'd like the cell in the row with the error to return the message Re-Check.

Ignore my previous codes.

Try to replicate this formula (or a more efficient formula) using VBA:

Code:
=IF(ISERROR(IF(D3="","",I3-F3)),"Re-check",(IF(D3="","",I3-F3)))
I don't know, but maybe the VBA code doesn't need the If iserror statement.

Thanks for trying to make some sense out of my nonsense,
Xrull
 
Last edited:
Upvote 0
ok, it's making more sense now,
that code was working for me, are your dates in a recognised excel date format?

To find out, save your workbook, then select the whole column with the dates and change the cell format to number, if it changes to a number like 39885.00 then it's valid, if it stays as a date then it's not.
 
Upvote 0
Jasonb,
I followed your instructions, and the dates changed to numbers (with the exception of the cell I want to show an error), and ran the formula again, but the cells returned #Name?.
I tried adjusting your code:
Code:
Sub Macro15() 'Invoice date to post date
 With Sheets("ENTRY")
      For a = 3 To Range("D" & Rows.Count).End(xlUp).Row
      Range("M" & a) = "=IF(D" & a & "="""","""",IFERROR(I" & a & "-L" & a & ",""Re-check"",I" & a & "-L" & a & ")))"
      Range("M" & a) = Range("M" & a).Value
      Next
      End With
 
End Sub
But my attempts are making people on this site cringe (it didn't work). If Excel police existed, I'd be doing life for mangling codes like this.
I thinking Excel doesn't like me:(
Thanks again,
Xrull
 
Last edited:
Upvote 0
Ok, made a couple of minor changes but nothing drastic, still can't see why it didn't work before

Data in column M entered by the macro.

Excel Workbook
DILM
3name13/03/200813/03/2009365
4name13/03/200813/03/2009365
5name13/03/200813/03/2009365
6name13/03/200813/03/2009365
7name13/03/200813/03/2009365
8name13/03/200813/03/2009365
9namenodate13/03/2009Re-check
10name13/03/200813/03/2009365
11name13/03/200813/03/2009365
12name13/03/200813/03/2009365
13namenodate13/03/2009Re-check
1413/03/200813/03/2009
15nodate13/03/2009
16name13/03/200813/03/2009365
17name13/03/200813/03/2009365
18name13/03/200813/03/2009365
19name13/03/200813/03/2009365
20name13/03/201013/03/2009Re-check
entry



Code:
Sub Macro15() 'Invoice date to post date
 With Sheets("Entry")
      For a = 3 To Range("D" & Rows.Count).End(xlUp).Row
      Range("M" & a) = "=IF(D" & a & "="""","""",IFERROR(L" & a & "-I" & a & ",""Re-check""))"
      If Range("M" & a).Value < 0 Then Range("M" & a) = "Re-check"
      Range("M" & a) = Range("M" & a).Value
      Next
      End With
 
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,979
Members
448,934
Latest member
audette89

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top