Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. Sub Button3_Click()
  2. Dim wb As Workbook: Set wb = ThisWorkbook
  3. Dim ws As Worksheet: Set ws = wb.Sheets("Master")
  4. Dim newws As Worksheet, sh As Worksheet, newname
  5. Dim query As Long, xst As Boolean, info As String
  6.  
  7. retry:
  8. xst = False
  9. newname = Application.InputBox("Enter Inmate Name and Number.", info, , , , , , 2)
  10. If newname = "False" Then Exit Sub
  11. For Each sh In wb.Sheets
  12. If sh.Name = newname Then
  13. xst = True: Exit For
  14. End If
  15. Next
  16. If Len(newname) = 0 Or xst = True Then
  17. info = "Sheet name is invalid. Please retry."
  18. GoTo retry
  19. End If
  20. ws.Copy after:=ws
  21. Set newws = ActiveSheet: newws.Name = sh
  22. End Sub
  23.  
  24. Dim wb As Workbook: Set wb = ThisWorkbook
  25. Dim ws As Worksheet: Set ws = wb.Sheets("Master")
  26. Dim NewName As String: NewName = ""
  27. Dim sh As Worksheet
  28.  
  29. Retry:
  30. NewName = Application.InputBox("Enter Inmate Name and Number.", info, NewName, , , , , 2)
  31. If NewName = "False" Then Exit Sub 'user shoose 'Cancel'
  32. For Each sh In wb.Sheets
  33. If NewName = sh.Name Or NewName = "" Then
  34. MsgBox "Sheet name is invalid. Please retry."
  35. GoTo Retry
  36. End If
  37. Next sh
  38. ws.Copy After:=ws
  39. With wb.Sheets("Master (2)")
  40. .Visible = True
  41. .Activate
  42. .Name = NewName
  43. End With
  44.  
  45. Application.ScreenUpdating = false
  46. ws.visible = xlSheetVisible
  47. ws.Copy after:=ws
  48. Set newws = ActiveSheet: newws.Name = sh
  49. ws.visible = xlsheethidden
  50. Application.ScreenUpdating = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement