ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   conditional input box for sheet name (https://www.excelbanter.com/excel-programming/343876-conditional-input-box-sheet-name.html)

shark102

conditional input box for sheet name
 
Hello

I created macro which works perfectly (thanks to this site also).
The only problem is that during running of that macro new worksheets are
created and named after string in particular cells.
It happens sometimes that string is that cell contains invalid characters or
is too long and stops the macro. Cells are always in the same colums so I
warned people using this macro to check before running it if this colums
contains valid strings and do find/replace but you know how it is.

is it possible (I should ask 'how to') : name worksheet after string in a
cell but if it is invalid string for worksheet name display input box and
name worksheet from input box.

below is a bit of code which I have at the moment (it is inside a loop if it
matters)

Selection.Copy
Sheets("Sheet1").Select
Sheets.Add
Range("A2").Select
ActiveSheet.Paste

Cells.find(What:="descr1", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False, SearchFormat:=False).Activate
Cells(ActiveCell.Row + 2, ActiveCell.Column).Select

ActiveSheet.Name = ActiveCell.Value




tiah

conditional input box for sheet name
 
make a little sub that will ask that

Sub NameCorrect(CellContent As String)
On Error Resume Next
ActiveSheet.Name = CellContent
Do While Err.Number 0
NewName = InputBox("Name not correct, enter new one")
Err.Clear
ActiveSheet.Name = NewName
Loop
End Sub



All times are GMT +1. The time now is 12:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com