Link to home
Start Free TrialLog in
Avatar of Andreas Hermle
Andreas HermleFlag for Germany

asked on

Set decimal tabstops on multiple tables using VBA

Dear Experts:

the below macro sets a decimal tab stop for the selected table cells and aligns the entries with the decimal tab.

I do not want to select the cells but run this macro on column 2 and 3 of a lot of tables.


Sub SetDecimalTabStop()
Dim MyTab As String
MyTab = InputBox("Location (Centimeter):", "Set Decimal Tab")
If Val(MyTab) > 0 Then
  With Selection.ParagraphFormat.TabStops
    .ClearAll
    .Add Position:=CentimetersToPoints(Val(MyTab)), _
      Alignment:=wdAlignTabDecimal, _
      Leader:=wdTabLeaderSpaces
  End With
End If
End Sub

Open in new window


Could somebody help me re-write this code / tweak it with the following requirements

1. An Inputbox lets the user determine which tables are to be worked on: Entries allowed are just numbers divided by a hyphen,
such as 1-7 or 2-9 or 4-5

2.  columns 2 and 3 of these tables will get these decimal tabs inserted.

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

Regards, Andreas
Avatar of Mike in IT
Mike in IT
Flag of United States of America image

Does the hyphen mean 1 through 7 or does it mean 1 and 7?

What if you want to use tables 1, 3, and 9 how would you designate that?

Can you provide a sample workbook?
Avatar of Andreas Hermle

ASKER

Hi Mike,

thank you very much for your post.

These are always contiguous ranges, i.e. it always means 2 thru 5 ,  for example

Also, I have provided a sample file

Thank you very much

Andreas

Sample_File_Several_Tables.docx
ASKER CERTIFIED SOLUTION
Avatar of Mike in IT
Mike in IT
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Mike,

very good job, Mike, thank you very much for your professional help. I really highly appreciate it.

Regards, Andreas