Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-02-2021, 01:41 PM
laith93 laith93 is offline Search for first occurrence of certain letter in beginning of a paragraph Windows 10 Search for first occurrence of certain letter in beginning of a paragraph Office 2019
Competent Performer
Search for first occurrence of certain letter in beginning of a paragraph
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Post Search for first occurrence of certain letter in beginning of a paragraph

Hi,
Look at this image


18.png
I have a list of references (bibliography) at the end of the document, which sorted alphabetically
I want to organize them in a professional way and put them in subgroups by inserting the corresponding letter before each group of references of a certain letter.
The above image is created manually

For example:
I want to search for the first occurrence of letter A in beginning of the first paragraph which starts with A letter, then insert letter A before this paragraph and apply the style "BibloChar" to it, which is present in the attachment file.
When A is finished jump to the B letter and do the same thing, and so and so, until finishing all characters.

I want the template of the code for letters A, B, and C, then I will complete the rest of the code.

Thanks a lot.
Attached Files
File Type: docx Sample.docx (18.9 KB, 7 views)
Reply With Quote
  #2  
Old 11-02-2021, 04:44 PM
Guessed's Avatar
Guessed Guessed is offline Search for first occurrence of certain letter in beginning of a paragraph Windows 10 Search for first occurrence of certain letter in beginning of a paragraph Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,161
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This looks like it works.
Code:
Sub AddLetterHeads()
  Dim iPar As Integer, sLett As String, aRng As Range, sPrev As String
  Set aRng = ActiveDocument.Range
  For iPar = aRng.Paragraphs.Count To 1 Step -1
    sLett = aRng.Paragraphs(iPar).Range.Characters(1)
    If iPar > 1 Then sPrev = aRng.Paragraphs(iPar).Previous.Range.Characters(1)
    If sPrev <> sLett Or iPar = 1 Then
      aRng.Paragraphs(iPar).Range.InsertBefore sLett & vbCr
      aRng.Paragraphs(iPar).Style = "BibloChar"   'the new paragraph
    End If
  Next iPar
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 11-02-2021, 06:17 PM
laith93 laith93 is offline Search for first occurrence of certain letter in beginning of a paragraph Windows 10 Search for first occurrence of certain letter in beginning of a paragraph Office 2019
Competent Performer
Search for first occurrence of certain letter in beginning of a paragraph
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
This looks like it works.
Wow, Mr. Andrew
It works by 100%
Thank you, That’s very kind of you
I can’t thank you enough
Thank you for your guidance and support
I will forever be beholden to you
Thank you, I really appreciate your help
Reply With Quote
Reply

Tags
vba code, vba find and replace, word vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for first occurrence of certain letter in beginning of a paragraph Replace a character only if it is at the beginning of the paragraph. donpopo Word 2 11-11-2018 11:32 PM
Search for first occurrence of certain letter in beginning of a paragraph Space tab at the beginning of each paragraph in a chapter village Word 3 07-20-2018 01:48 AM
Search for first occurrence of certain letter in beginning of a paragraph Wildcards - Sequence of Numbers at the Beginning of Each Paragraph qubie Word 1 11-30-2017 02:03 PM
Search for first occurrence of certain letter in beginning of a paragraph search for consecutive words beginning with capital letter cheech1981 Word 7 11-24-2017 12:50 PM
Search for first occurrence of certain letter in beginning of a paragraph How to keep a word with capitalized first letter, but not at the beginning of a sentence? xiangwulu Word 4 10-31-2014 09:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft