Hi,
Can anyone help me to understand are we able to write a macro to read the last sentence of 2 alphabets and filter? I just want the macro help to pick the data end with ES to put in column D as wk1 and end with Prod in column D as wk2.
Currently, I have to use formula to split the last 2 and 4 letters in another column, then filter one by one. Is there any faster way to do that?
File attached Example:
column B,
consolidate_ES
consolidate_Prod
consolidate_xx
consolidate_Prod
Thank you & Regards
CY
VIP
Trusted Members
June 25, 2016
Hi Sunny,
Thank you for your suggestion. The reason being i need to crate macro because, this is only part of the process. there are thousand of rows & 25 columns data which need to filter, get the correct item and create a pivot table. Thus, I have to think a way to simply it and get macro to run for the whole report.
Let me try to use the formula that you suggested. After I apply the formula to pick up the ending letters, I will need to filter those ending with ES, create a pivot table and ending with Prod, create another pivot table in order to work on the data analysis.
Any idea, can write a code to pick those end with ES and Prod to create the pivot table separately?
Thank you.
CY
VIP
Trusted Members
June 25, 2016
Trusted Members
December 20, 2019
I agree with sunny for small, adhoc data sets filter is the easiest method but if it is repetitive and repeatable then a Macro can help.
Attached is a quick macro that should put the detail you want in column G (this can be changed in the code by changing the offset(0,5) to whatever column you want relative to column B
Option Explicit
Sub SplitAndPop()
Dim lr As Long 'last row
Dim tr As Range 'type range (where the data is)
Dim tc As Range 'type cell (cell loop)
Dim us As Integer 'underscore letter count in case different words are used
lr = Cells(Rows.Count, 1).End(xlUp).Row 'find last row
Set tr = Range("b2:b" & lr) 'set type range
For Each tc In tr 'loop through all cells in the type range
us = InStr(tc.Value, "_") 'finds the letter number of the underscore
If Right(tc, Len(tc) - us) = "ES" Then 'checks if the end bit is ES, PROD, Pre or End then assigns a new tag
tc.Offset(0, 5) = "wk1"
End If
If Right(tc, Len(tc) - us) = "Prod" Then
tc.Offset(0, 5) = "wk2"
End If
If Right(tc, Len(tc) - us) = "Pre" Then
tc.Offset(0, 5) = "TBD"
End If
If Right(tc, Len(tc) - us) = "End" Then
tc.Offset(0, 5) = "TBD"
End If
Next tc
End Sub
Purfleet
Answers Post
1 Guest(s)