Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-15-2021, 05:09 AM
Guessed's Avatar
Guessed Guessed is offline Split function by comma and hyphen simultaneously Windows 10 Split function by comma and hyphen simultaneously Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,166
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

Try this version


Code:
Sub DeleteMultiplePagessssssssssssss()
'Delete Multiple Pages by displaying Inputbox

  Dim objRange As Range, strPage As String, objDoc As Document, nSplitItem() As String, iCounter As Integer

  Application.ScreenUpdating = False
 
    ' Initialize and enter page numbers of pages to be deleted.
    Set objDoc = ActiveDocument
    strPage = InputBox("Enter the page numbers of pages to be deleted: " & vbNewLine & _
              "use comma to separate numbers", "Delete Pages", "For example: 1,3")
    strPage = funExpandDashes(strPage)
    nSplitItem = Split(strPage, ",")
  
    ' Find specified pages and highlight their contents.
    For iCounter = UBound(nSplitItem) To 0 Step -1
      With objDoc
        Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute, Count:=nSplitItem(iCounter)
        Set objRange = .Bookmarks("\Page").Range
        objRange.Delete
      End With
    Next iCounter
 
  Application.ScreenUpdating = True
End Sub

Function funExpandDashes(strPage As String) As String
  Dim arrOuter() As String, iMin As Integer, iMax As Integer, arrInner() As String, sExpand As String
  Dim x As Integer, y As Integer

  strPage = Replace(strPage, " ", "")     'make sure there are no spaces
  arrOuter = Split(strPage, ",")
  For x = LBound(arrOuter) To UBound(arrOuter)
    arrInner = Split(arrOuter(x), "-")
    If UBound(arrInner) > LBound(arrInner) Then
      sExpand = arrInner(0)
      For y = CInt(arrInner(0)) + 1 To CInt(arrInner(1))
        sExpand = sExpand & "," & y
      Next y
      arrOuter(x) = sExpand
    End If
  Next x
  funExpandDashes = Join(arrOuter, ",")
End Function
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #2  
Old 08-15-2021, 05:30 AM
laith93 laith93 is offline Split function by comma and hyphen simultaneously Windows 10 Split function by comma and hyphen simultaneously Office 2019
Competent Performer
Split function by comma and hyphen simultaneously
 
Join Date: Jul 2021
Posts: 117
laith93 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
Try this version
Fantastic,
Thank you so much, Mr. Andrew, the code works fine.

Just I want to increase my info in VBA, why we used this line again

Code:
 nSplitItem = Split(strPage, ",")
Also, the delimiter of split function is "," not ", & -" after editing the code
Can you explain as you can, otherwise ignore it.

Thank you again
Reply With Quote
Reply

Tags
word 19, word vba, word vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Split function by comma and hyphen simultaneously Mistake in the help file for String "Split Function"? John 4 Word VBA 6 11-19-2020 06:02 AM
Hyphen until the end of the row abc3132 Word 13 10-31-2019 04:36 AM
Split function in Excel (split the screen) Officer_Bierschnitt Excel 1 07-05-2017 07:02 AM
Split function not working as I expect??!! XmisterIS Word VBA 9 04-08-2014 04:41 PM
Split function by comma and hyphen simultaneously Cross-reference function to update bullet header and number simultaneously dljenks Word 1 01-03-2014 01:38 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:59 PM.


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