Inputbox to enter column number that gets deleted

below code prompts a user to enter a column number, this column then gets subsequently deleted on all tables (all of them have identical numbers of columns).

I would like to have a better inputbox error handling, i.e. ...

(1) just integers greater than 0 are allowed as entry
(2) If an integer greater than the maximum count of columns is entered, a msgbox should say that the number entered is greater than the max. number of columns and the inputbox is to re-appear.

Help is much appreciated. Thank you very much in advance.

Regards, Andreas

Sub AllTables_Delete_One_Column()Dim tbl As TableDim ColumnNumberDelete As String'Just numbers are allowed and the number should be between 1 and maximum count of columns)Application.ScreenUpdating = FalseColumnNumberDelete = Inputbox("Which column number is to be deleted?", "Deletion of Column")If ColumnNumberDelete = "" Then Exit SubFor Each tbl In ActiveDocument.Tables tbl.Columns(ColumnNumberDelete).DeleteNextEnd Sub

It seems to me there is an implicit need to preTest all tables to find an acceptable number for the columns since ALL tables need to have that column number ... we could assume the tables are all the same size but the small amount of processing to be sure will prevent an error:

Sub AllTables_Delete_One_Column()Dim intColCount As IntegerDim tbl As TableDim ColumnNumberDelete As VariantDim bolOK As Boolean'Just numbers are allowed and the number should be between 1 and maximum count of columns) Application.ScreenUpdating = False' Initialise the loop control to prevent excessive column number intColCount = 99 For Each tbl In ActiveDocument.Tables If tbl.Columns.Count < intColCount Then intColCount = tbl.Columns.Count Next bolOK = False Do While Not bolOK ColumnNumberDelete = InputBox("Which column number is to be deleted?", "Deletion of Column") If ColumnNumberDelete = "" Then Exit Sub bolOK = (IsNumeric(ColumnNumberDelete) And (ColumnNumberDelete >= 1) And (ColumnNumberDelete <= intColCount)) Loop For Each tbl In ActiveDocument.Tables tbl.Columns(ColumnNumberDelete).Delete NextEnd Sub

thank you very much for your post. OOOPs, I should have stated, that all of the tables have the same number of columns. I am sorry about this. Thank you very much for considering that it could be different. I will do some testing this afternoon.

Hi Rgonzo: thank you very much. I will do some testing and then let you know.

A few years ago I was very much a beginner at VBA, and that very much remains the case today. I'll do my best to explain things as I go in the hope that other beginners can follow. If you just want to check out a tool that creates a Select Case fu…

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents. The steps to find the Templates folder path are …