Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2014, 05:41 AM
rsrasc rsrasc is offline Looking Again for Another Code/Macro Windows 7 64bit Looking Again for Another Code/Macro Office 2010 64bit
Competent Performer
Looking Again for Another Code/Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default Looking Again for Another Code/Macro

Hi all,
Here is the situation. I have a document (call this document #1) with 75 questions, with the following format:

Question #1 (ACCCC.101111REG)
Question #2 (ACCCC.101115REG-SIM)
Question #3 (ACCCC.900537REG-P2-AR)
......
Question #75 (ACCCC.910888REG-P2-AR)

Below is the output I was looking for and a solution was given to me with the following wildcard:
Find = Question #([0-9]@) \(ACCCC*\)
Replace = \1.


1.
2.
3.
4.
...
75.
================================================== ===============
Now, I have a second document (call this document #2) with 40 questions, with the same format as the one above (notice this one also starts with Question # 1).
Question #1 (ACCCC.1011201)
Question #2 (ACCCC.1011305-SIM)
Question #3 (ACCCC.900522037-P2-AR)
......
Question #40 (ACCCC.910888REG-P2-AR)

I would like to know if there is a way to convert Question #1 to Question #76 and so on with a code/macro.
The output will look like this:



Question #76 (ACCCC.1011201)
Question #77 (ACCCC.1011305-SIM)
Question #78 (ACCCC.900522037-P2-AR)
......
Question #115 (ACCCC.910888REG-P2-AR)

As always thank you for your support.

Cheers!
Reply With Quote
  #2  
Old 10-26-2014, 02:08 PM
macropod's Avatar
macropod macropod is offline Looking Again for Another Code/Macro Windows 7 64bit Looking Again for Another Code/Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You could use something like:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
i = CLng(InputBox("Starting#?"))
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "Question #([0-9]@) \(ACCCC*\)"
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .Text = Replace(.Text, Split(.Text, " ")(1), "#" & i)
    i = i + 1
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 10-26-2014, 02:35 PM
rsrasc rsrasc is offline Looking Again for Another Code/Macro Windows 7 64bit Looking Again for Another Code/Macro Office 2010 64bit
Competent Performer
Looking Again for Another Code/Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Super!!!! Working great. Good job!

Cheers!!!
Reply With Quote
  #4  
Old 11-15-2014, 09:42 AM
rsrasc rsrasc is offline Looking Again for Another Code/Macro Windows 7 64bit Looking Again for Another Code/Macro Office 2010 64bit
Competent Performer
Looking Again for Another Code/Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

I would like to know if the below code can be modify for the following sequence of numbers in a document. For example:

1.
2.
3.
4.
5.

To start with any number:

To:

11.
12 .
13.
14.
15.

Or start with"

20.
21.
22.
23.
24.

Thanks!

PHP Code:
Sub Demo()
Application.ScreenUpdating False
Dim i 
As Long
CLng(InputBox("Starting#?"))
With ActiveDocument.Range
  With 
.Find
    
.ClearFormatting
    
.Replacement.ClearFormatting
    
.Text "Question #([0-9]@) \(ACCCC*\)"
    
.Replacement.Text ""
    
.Forward True
    
.Wrap wdFindStop
    
.Format False
    
.MatchWildcards True
    
.Execute
  End With
  
Do While .Find.Found
    
.Text Replace(.TextSplit(.Text" ")(1), "#" i)
    
1
    
.Collapse wdCollapseEnd
    
.Find.Execute
  Loop
End With
Application
.ScreenUpdating True
End Sub 
Reply With Quote
  #5  
Old 11-15-2014, 11:04 PM
macropod's Avatar
macropod macropod is offline Looking Again for Another Code/Macro Windows 7 64bit Looking Again for Another Code/Macro Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

All you need do is change the Find expression, to:
.Text = "<[0-9]@."
and change:
.Text = i & "."
PS: when posting code, please use the code tag (indicated by the # button), not the PHP tag (indicated by the PHP button).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 11-16-2014, 05:47 AM
rsrasc rsrasc is offline Looking Again for Another Code/Macro Windows 7 64bit Looking Again for Another Code/Macro Office 2010 64bit
Competent Performer
Looking Again for Another Code/Macro
 
Join Date: Mar 2014
Location: Germany
Posts: 148
rsrasc is on a distinguished road
Default

Did the changes and working great!

Thank you again for your support.

Cheers!



Code:
Sub Demo()
Application.ScreenUpdating = False
Dim i As Long
i = CLng(InputBox("Starting#?"))
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "<[0-9]@."
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = False
    .MatchWildcards = True
    .Execute
  End With
  Do While .Find.Found
    .Text = i & "."
    i = i + 1
    .Collapse wdCollapseEnd
    .Find.Execute
  Loop
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Style in Use Macro-Need Help Optimizing Code freda0255 Word VBA 4 08-04-2014 07:35 PM
Looking Again for Another Code/Macro VBA Code for adding Macro to QAT OTPM Project 4 08-22-2013 01:33 PM
Need Macro code for Outlook gbaker Outlook 0 04-11-2013 10:29 AM
Looking Again for Another Code/Macro I need help with macro...code needed for automatic sorting chefmate Excel Programming 1 08-26-2012 01:04 AM
Excel 2007 - formula or macro/vba code required wrighty50 Excel Programming 3 05-13-2012 02:24 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:38 AM.


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