VBA subtracting two dates and creating a new column

Palucci

Banned user
Joined
Sep 15, 2021
Messages
138
Office Version
  1. 365
Platform
  1. Windows
I have a function, I would like it to subtract dates from me and create a new column. However, it does not work, it shows me an error here
VBA Code:
.Value = Evaluate("if({1}," & .Offset(, -2).Address & "-" & .Offset(, -1).Address & ","""")")
"Application - definied or object - definied error :
VBA Code:
   With wbMe.Sheets("Arkusz3").Range("G2", Range("A" & Rows.Count).End(xlUp).Offset(, 1))
      .Value = Evaluate("if({1}," & .Offset(, -2).Address & "-" & .Offset(, -1).Address & ","""")")
   End With
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
I have a function, I would like it to subtract dates from me and create a new column. However, it does not work, it shows me an error here
VBA Code:
.Value = Evaluate("if({1}," & .Offset(, -2).Address & "-" & .Offset(, -1).Address & ","""")")
"Application - definied or object - definied error :
VBA Code:
   With wbMe.Sheets("Arkusz3").Range("G2", Range("A" & Rows.Count).End(xlUp).Offset(, 1))
      .Value = Evaluate("if({1}," & .Offset(, -2).Address & "-" & .Offset(, -1).Address & ","""")")
   End With
cross post : VBA subtracting two dates and creating a new column
 
Upvote 0
This line
VBA Code:
With wbMe.Sheets("Arkusz3").Range("G2", Range("A" & Rows.Count).End(xlUp).Offset(, 1))
is creating a range from B2:G & last row in A.
You are then offsetting that range by -2 columns which you cannot do for col B
 
Upvote 0
This line
VBA Code:
With wbMe.Sheets("Arkusz3").Range("G2", Range("A" & Rows.Count).End(xlUp).Offset(, 1))
is creating a range from B2:G & last row in A.
You are then offsetting that range by -2 columns which you cannot do for col B
im little lost. I wanted to subtract columns E and D and put result in G
 
Upvote 0
Which column should be subtracted from which?
 
Upvote 0
In that case try
VBA Code:
   With wbMe.Sheets("Arkusz3").Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row)
      .Value = .worksheet.Evaluate("if({1}," & .Offset(, -3).Address & "-" & .Offset(, -2).Address & ","""")")
   End With
 
Upvote 0
Solution
That was what it was about! Is there a chance to add a column name?
In that case try
VBA Code:
   With wbMe.Sheets("Arkusz3").Range("G2:G" & Range("A" & Rows.Count).End(xlUp).Row)
      .Value = .worksheet.Evaluate("if({1}," & .Offset(, -3).Address & "-" & .Offset(, -2).Address & ","""")")
   End With
That was what it was about! Is there a chance to add a column name?
 
Upvote 0
What do you mean?
For example now i have some like that : And i would like add name to headers e.g: " Diffrence"
1643724174213.png
 
Upvote 0

Forum statistics

Threads
1,215,256
Messages
6,123,906
Members
449,132
Latest member
Rosie14

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