VBA to determine Quarter and year from range of dates

Godders199

Active Member
Joined
Mar 2, 2017
Messages
313
Office Version
  1. 2013
Hello, currently i have the following which populates in column O the latest quarter and year from a range of dates in columns K-M

LR = Range("a" & Rows.Count).End(xlUp).row
Range("o2").Select
ActiveCell.FormulaR1C1 = "=""q"" & ROUNDUP(MONTH(MAX(RC[-4]:RC[-2]))/3,0)&""-""&YEAR(MAX(RC[-4]:RC[-2]))"
Range("O2").Copy
Range("o2:eek:" & LR).PasteSpecial xlPasteAll
Application.CutCopyMode = False

What i would really like to do is amend this , so if the result of the formula equals daterng4 it returns "0" instead of quarter and year.

I already haveDaterng4 set up for other coding.


Daterng4 = Worksheets("homepage").Range("R1") 'current quarter'

Is this possible? , any help apprciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Can you replace

Code:
[COLOR=#333333]Range("o2").Select[/COLOR]
[COLOR=#333333]ActiveCell.FormulaR1C1 = "=""q"" & ROUNDUP(MONTH(MAX(RC[-4]:RC[-2]))/3,0)&""-""&YEAR(MAX(RC[-4]:RC[-2]))"
[/COLOR]

with

Code:
If [COLOR=#333333]Daterng4 <> 0 then[/COLOR]
[COLOR=#333333]Range("o2").[/COLOR][COLOR=#333333]FormulaR1C1 ="=""q"" & ROUNDUP(MONTH(MAX(RC[-4]:RC[-2]))/3,0)&""-""&YEAR(MAX(RC[-4]:RC[-2]))"
else 0
end if
[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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