?
Solved

Inputbox to enter column number that gets deleted

Posted on 2013-07-01
4
Medium Priority
?
353 Views
Last Modified: 2013-07-05
Dear Experts:

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 Table
Dim ColumnNumberDelete As String
'Just numbers are allowed and the number should be between 1 and maximum count of columns)

Application.ScreenUpdating = False

ColumnNumberDelete = Inputbox("Which column number is to be deleted?", "Deletion of Column")

If ColumnNumberDelete = "" Then Exit Sub
    
For Each tbl In ActiveDocument.Tables

           tbl.Columns(ColumnNumberDelete).Delete
    
Next

End Sub

Open in new window

0
Comment
Question by:AndreasHermle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 1400 total points
ID: 39300179
Hi,

pls examine this doc

I have created an Input user form

Regards
DelCol.doc
0
 
LVL 59

Assisted Solution

by:Chris Bottomley
Chris Bottomley earned 600 total points
ID: 39301218
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 Integer
Dim tbl As Table
Dim ColumnNumberDelete As Variant
Dim 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
    Next

End Sub

Open in new window


Chris
0
 

Author Comment

by:AndreasHermle
ID: 39301436
Hi Chris,

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.

Regards, Andreas
0
 

Author Closing Comment

by:AndreasHermle
ID: 39302273
Dear both,

both codes work fine. Thank you very much for your professional help.

It is great to have both approaches, a concise code by Chris and a more 'complicated' one using an Input User Form.

Again thank you very much for your great help.

Regards, Andreas
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question