How to match quarter data with the correct quarter?

Waimea

Active Member
Joined
Jun 30, 2018
Messages
465
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a data table with 3 columns, name, value and year and quarter.

NameValueYear & quarter
Event A502021 Q1
Event B452021 Q3
Event C522021 Q4
Event D492022 Q2

And I have a table with timevalues:

Timevalue
2021 Q1
2021 Q2
2021 Q3
2021 Q4
2022 Q1
2022 Q2
2022 Q3

How can I in a easy way (with VBA) place the events at the right place in my timetable?

TimevalueNameValue
2021 Q1Event A50
2021 Q2
2021 Q3Event B45
2021 Q4Event C52
2022 Q1
2022 Q2Event D49

All suggestions are very welcome!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I found that FILTER function kind of does what I am trying to do.

However, I am looking for a VBA solution.

Any suggestion on what functions that I could use?
 
Upvote 0
An alternative is to use Power Query and join the two tables on left outer join

Book2
ABCDEF
1NameValueYear & quarterTimevalue
2Event A502021 Q12021 Q1
3Event B452021 Q32021 Q2
4Event C522021 Q42021 Q3
5Event D492022 Q22021 Q4
62022 Q1
72022 Q2
82022 Q3
9
10
11TimevalueTable1.NameTable1.Value
122021 Q1Event A50
132021 Q2
142021 Q3Event B45
152021 Q4Event C52
162022 Q1
172022 Q2Event D49
182022 Q3
Sheet1


Power Query:
let
    Source = Table.NestedJoin(Table2, {"Timevalue"}, Table1, {"Year & quarter"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(Source, "Table1", {"Name", "Value"}, {"Table1.Name", "Table1.Value"})
in
    #"Expanded Table1"
 
Upvote 0
Hi alansidman,

thank you for your reply!

I am not great with powerquery but I will try your solution tomorrow!

I am trying to use INDEX & MATCH functions to get what I want.

I have an odd number of matches depending on what events I am looking at.

Perhaps there is a good way to use VBA and INDEX & MATCH?
 
Upvote 0
I got it kind of working with index and match formuals in the spreadsheet.

However, I want to try a VBA solution.

VBA Code:
=INDEX($AP$387:$AP$396;MATCH(AC384;$AU$387:$AU$396;0))

and

VBA Code:
=INDEX($AQ$387:$AQ$396;MATCH(AC384;$AU$387:$AU$396;0))

These are my current formulas and they work, I am trying to create them in VBA.

I would like to assign quarters to events where the year is presented but the quarter is omitted.

So if first data entry is Event A, 50, and 2021 Q2, I want to assign Q3 and Q4.

If the third data entry is 2022 Q1, I want to assign omitted quarters Q2, Q3 and Q4.
 
Upvote 0
Data A1:C5
Second table A9:C16

Code
VBA Code:
Sub TrandferData()
Dim TR As Long
Dim SeachRng As Range

Set SearchRng = Range("C1:C5")

For TR = 10 To 16

Set Frng = SearchRng.Find(What:=Range("A" & TR), After:=Range("C1"), LookIn:=xlFormulas, LookAt:= _
        xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=False)

If Not Frng Is Nothing Then
Range("B" & TR) = Range("A" & Frng.Row)
Range("C" & TR) = Range("B" & Frng.Row)
End If

Next TR

End Sub
 
Upvote 0
Hi kvsrinivasamurthy,

thank you for your reply. Your code works really well!

A follow up question, what happens if two events have the same year and quarter?
 
Upvote 0
Hi,

thank you for your reply!

NameValueYear and quarter
Event A502021 Q1
Event B462021 Q2
Event C392021 Q3
Event D412021 Q3
Event E482022 Q1
Event F512022 Q3
Event G482023 Q1

Event C and Event D both have the same year and quarter, 2021 Q3.

I am not sure on what to do when two events have the same year and quarter, perhaps just add +1 to the last quarter?

So event D would be 2021 Q4! :)

I am plotting the events on a timeline, perhaps I could change the quarters to contain two units? I tried and it didn't lock any good!

So adding one quarter would be a good way!
 
Last edited:
Upvote 0
Perhaps there is a way to count each occurence of year and quarter and then add +1 quarter if there are two quarters with the same year?
 
Upvote 0

Forum statistics

Threads
1,215,388
Messages
6,124,648
Members
449,177
Latest member
Sousanna Aristiadou

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