• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Can we write a macro to read the last sentence of 2 alphabets and filter?|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Can we write a macro to read the last sentence of 2 alphabets and filter?|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosCan we write a macro to read the la…
sp_PrintTopic sp_TopicIcon
Can we write a macro to read the last sentence of 2 alphabets and filter?
Avatar
Guest
Guest
Guests
1
January 13, 2020 - 6:27 pm
sp_Permalink sp_Print

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

sp_AnswersTopicSeeAnswer See Answer
Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
2
January 14, 2020 - 9:16 am
sp_Permalink sp_Print

Why don't you just create a table and then do a VLOOKUP?

Consolidate_ES wk1
Consolidate_Prod wk2
Consolidate_Pre TBD
Consolidate_End TBD

If you need the word after the underscore you can try SUBSTITUTE(B2,"Consolidate_","")

Hope this helps.

Sunny

Avatar
Guest
Guest
Guests
3
January 14, 2020 - 9:52 am
sp_Permalink sp_Print sp_EditHistory

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

Avatar
SunnyKow
Puchong, Malaysia

VIP
Members


Trusted Members
Level 8
Forum Posts: 1432
Member Since:
June 25, 2016
sp_UserOfflineSmall Offline
4
January 14, 2020 - 12:22 pm
sp_Permalink sp_Print

Hi CY

Then just create multiple Pivot tables straight from your data and filter each one for the required type.

No need to do anything extra at all.

Sunny

Avatar
Purfleet
England
Member
Members


Trusted Members
Level 4
Forum Posts: 412
Member Since:
December 20, 2019
sp_UserOfflineSmall Offline
5
January 14, 2020 - 5:18 pm
sp_Permalink sp_Print sp_EditHistory

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

sp_AnswersTopicAnswer
Answers Post
Avatar
Guest
Guest
Guests
6
January 14, 2020 - 5:29 pm
sp_Permalink sp_Print

Hi Sunny,

Alright. Thank you.

The SUBSTITUTE(B2,"Consolidate_","") is very useful. 🙂

Thank you.

Avatar
Guest
Guest
Guests
7
January 15, 2020 - 11:52 pm
sp_Permalink sp_Print

Thank you Purfleet. Is really help. Appreciated.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Jeanine Hagge
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
Jessica Stewart: 205
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Othman AL MUTAIRI
Misael Gutierrez Sr.
Attif Ihsan
Kieran Fee
Murat Hasanoglu
Brett Dryland
Saeed Aldousari
Bhuwan Devkota
Kathryn Patton
Maria Conatser
Forum Stats:
Groups: 3
Forums: 24
Topics: 6222
Posts: 27293

 

Member Stats:
Guest Posters: 49
Members: 31917
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.