• 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

Split into Sheets then into files|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Split into Sheets then into files|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 & MacrosSplit into Sheets then into files
sp_PrintTopic sp_TopicIcon
Split into Sheets then into files
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
1
December 23, 2020 - 9:23 am
sp_Permalink sp_Print

Hello,

Please can you help me urgently. 

Attached macro have two modules and I need your help in module 1 "Splitdatatosheets", this module get first sheet "Template" and Split it into many sheets based on Company Name column.

As you know the sheet name should not exceed this length "31", and there are some names exceed this length, so macro can't create sheet with name.

Please can you help me to update the macro module 1 "Splitdatatosheets" as below.

1- If the company name contain Special Characters, when macro create sheets names, should remove Special Characters. "No need to remove Space"

Ex: Raychem RPG (P) Ltd.   so the sheet name should be Raychem RPG P Ltd

2- After removing all Special Characters and macro found the name still exceed this length "31", macro can remove all Characters after last space.

Ex: Integrated Silicon Solutions, Inc. the length is 32 after removing Special Characters, so macro result should be Integrated Silicon Solutions

Ex: Visual Communications technology Company, LLC the length is 44 and if macro remove after last space will be Visual Communications technology Company and length is 40, so macro should remove all Characters after previous space and so on. so in this case the name should be Visual Communications

I hope you understand me. and thank you very much.

Thanks;

Marsil

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
December 23, 2020 - 3:05 pm
sp_Permalink sp_Print

Hi Marsil,

Here is a function that can clean the text and keep it under 30 chars:
Note that () are not illegal chars in a sheet name.

Function CleanName(ByVal NewName As String) As String
Dim Arr As Variant, Itm As Variant

Arr = Array("/", "\", "?", "*", "[", "]")
For Each Itm In Arr
If InStr(1, NewName, Itm, vbTextCompare) > 0 Then NewName = Replace(NewName, Itm, "", , , vbTextCompare)
Next Itm

Do Until Len(NewName) <= 30
If InStrRev(NewName, " ", , vbTextCompare) = 0 Then Exit Do
NewName = Left(NewName, InStrRev(NewName, " ", , vbTextCompare) - 1)
Loop

CleanName = Left(NewName, 30) 'in case there are no more spaces and len is still over 30
End Function

sp_AnswersTopicAnswer
Answers Post
Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
3
December 23, 2020 - 6:07 pm
sp_Permalink sp_Print

Hi Catalin,

How kind you are to help me. Thank you very much.

Please can u add this code in attached macro as I face issue after I inserted the code.

Thank you very much; your support is greatly appreciated. 

Thanks,

Marsil

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
December 23, 2020 - 7:53 pm
sp_Permalink sp_Print

It's a function, all you have to do is to paste it in any standard module, then call the function from your code to clean the text:

CleanedString=CleanName("The text string that contains illegal chars, longer than 30 chars")

You can even use it in excel cells, like any function.

Avatar
Marsil Sarvis
Member
Members
Level 0
Forum Posts: 73
Member Since:
September 6, 2019
sp_UserOfflineSmall Offline
5
December 24, 2020 - 10:01 am
sp_Permalink sp_Print

That's a huge help - thanks!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Andy Kirby, Ben Hughes, Francis Drouillard
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
yashal minahil
Oluwadamilola Ogun
Yannik H
dectator mang
Francis Drouillard
Orlando Inocente
Jovitha Clemence
Maloxat Axmatovna
Ricardo Freitas
Marko Meglic
Forum Stats:
Groups: 3
Forums: 24
Topics: 6201
Posts: 27185

 

Member Stats:
Guest Posters: 49
Members: 31861
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.