1

I am writing a macro which compares two sets of values and warns the user if any differences are present. When a difference is found, I want the user to input their comment. To make it easy for them to understand what I'm asking about, I want to show all the numbers inside the InputBox I use to get the comment. Example InputBox I want to get could look the following way:

Difference between warehouse and accounting records! See details below, insert reason.

Product: Toyota Corolla

------------------------------
|Item   |Warehouse|Accounting|
------------------------------
|Wheel  |        3|         3|
------------------------------
|Engine |        2|         3|
------------------------------
|Door   |        7|         7|
------------------------------
|Gearbox|        5|         5|
------------------------------
|Roof   |        4|         3|
------------------------------

In this case, the alert is caused by different values for Roof and Engine. The numbers filling the table are stored in variables. How to make such table which will look clear to user who has to enter the comment?

Community
  • 1
  • 1
jacek_wi
  • 455
  • 1
  • 6
  • 20
  • You could try it this way: http://stackoverflow.com/questions/28190915/display-a-table-in-the-userform-by-extracting-from-excel-sheet – Darren Bartrup-Cook Dec 05 '16 at 11:46
  • @Jordan haven't tried much, as I got stuck more or less right at the start. Searched for help but all I could find was about displaying a table which is part of your workbook, not building a completely new one. – jacek_wi Dec 05 '16 at 12:07
  • 4
    Why not create a userform? If you haven't done it before it really isn't that much work (and tutorials are easily found). Input/Message boxes aren't the best if you need to show formatted data to the user. – John Coleman Dec 05 '16 at 12:32

1 Answers1

5

After some extra research I found that the key command I was missing was vbTab

The below code returns an input box with table formatted nicely enough for clear data presentation.

Sub TestMsg()
    Dim testcom As String
    testcom = InputBox("Enter answer" & vbNewLine & "axx" & vbTab & "b" & vbNewLine & "c" & vbTab & "xxd")
    MsgBox testcom
End Sub
jacek_wi
  • 455
  • 1
  • 6
  • 20
  • 1
    This is a nice, quick-and-dirty solution. If it is for others to use at work I would recommend trying to tweak it, perhaps as a user-form. It is always nice to have a bit of professional polish. – John Coleman Dec 05 '16 at 15:55