0

enter image description hereI have a spreadsheet that contains data that has to be put on a Notepad, but the spacing never lines up right. I have tried using text padding but am unable to figure out how to space this out. I want the users to be able to enter the information then just be able to copy and paste over to Notepad without spending hours making the information line-up to the headers. Any help is appreciated. I uploaded a picture of what happens when enter image description hereit transfers to Notepad. enter image description here

5
  • Are you creating the txt by code?
    – NielsNet
    Mar 25, 2018 at 0:46
  • No the text is being entered manually into each cell.
    – Bill
    Mar 25, 2018 at 2:28
  • I mean the file in notepad
    – NielsNet
    Mar 25, 2018 at 2:54
  • No I'm just copying from the Excel sheet and putting it into notepad.
    – Bill
    Mar 25, 2018 at 3:18
  • Just to help you understand what the problem is: When you copy a range from excel to Notepad, columns will be replaced by tabs to have a delimiter. You can think of it like Excel inserting a tab for each vertical line (i.e. cell boundary) in your row. So a row in Excel that is A | B | C becomes A<tab>B<tab>C. Now as you might know from using Word, tabs have a fixed width, so if your text changes in length the tab will "ratchet" one further back or forth. You can avoid this by formatting your text appropriately (e.g. always using the fixed-length YYYY-MM-DD hh:mm for dates). Mar 25, 2018 at 15:47

5 Answers 5

3

Without VBA one option will be as below:

Set up a table like below.

A                B                C              D
20               15               15             15 
Date / Time      Type             ID             Duration       Output
3/25/2018 13:49  Outgoing         1234567890     32s            Formula Here

In Row 1, set the widths as you need and then in "Formula Here" place following formula:

=CONCATENATE(IF(A3="",REPT(" ",$A$1),REPLACE(REPT(" ",$A$1),1,LEN(TEXT(A3,"dd/mm/yyyy hh:mm")),TEXT(A3,"dd/mm/yyyy hh:mm")),REPLACE(REPT(" ",$B$1),1,LEN(B3),B3),REPLACE(REPT(" ",$C$1),1,LEN(C3),C3),REPLACE(REPT(" ",$D$1),1,LEN(D3),D3))

You can then copy this column and paste to Notepad as and when needed.

2
  • Except when there is no Date/Time it still leaves 01/00/1900 00:00
    – Bill
    Mar 25, 2018 at 16:36
  • You can add an IF condition to column A to only pass the white space if the field is empty.
    – Eliot K
    Mar 25, 2018 at 21:51
2

Assuming you don’t have to worry about line breaks in any of the columns, a simplistic recommendation would be to set up another sheet/tab with a formula like this:

={TEXTJOIN(“ “, FALSE, ‘SHEET1’!A2 & REPT(“ “, MAX(LEN(‘SHEET1’!A:A))), ‘SHEET1’!B2 & REPT(“ “, MAX(LEN(‘SHEET1’!B:B))), ... ‘SHEET1’!X2 & REPT(“ “, MAX(LEN(‘SHEET1’!X:X))))}

You should replace the ‘...’ and references to something appropriate. People could then copy from the this tab. This formula would have to be included for each row in the other spreadsheet. This can also be improved with VBA.

1
  • I don't understand where I would put this.
    – Bill
    Mar 25, 2018 at 19:52
2

If you're creating the excel file then the easiest option would be to offer an alternative export in txt format.
The not so beautiful alternative would be to get the lenght of of the longest value (in chars) and add the missing amount of spaces behind the other values. However I didn't check whether excel trima vales when copying. In both cases you won't have perfect alignment if the editor used to open the data uses a font that is not monospaced. CSV might be an alternative (as it can be opened by both text editors and cell file editors)

The solution you opt for may vary depending on the environment your file is used.

But if you want your users to enter the data manually as stated in your question you might want to use VBA and offer an export button that allows users to create a txt file from excel.

1

Seems like you just have the spreadsheet set up inefficiently.

Instead of having a separate column for the different types, just have a column called "Type" and another called "ID", and never leave any cells blank, e.g. something like:

Date/Time   Type        ID          etc...
1/1/18      Outgoing    1234567890
1/2/18      Incoming    1234567890

Another option is to save the file as a .csv file type (comma-separated value), then when you open in notepad, the entries are all separated by commas, and you can easily go back and forth between Excel and Notepad.

2
  • That is a great idea actually! Although I am still curious about being able to run a code with the spacing. But this works! Thank you!
    – Bill
    Mar 25, 2018 at 0:56
  • Actually, I take that back. It doesn't work. I still need some type of code to pad the spacing.
    – Bill
    Mar 25, 2018 at 2:26
0

Another option is to save your spreadsheet as Formatted Text (Space delimited)( *.prn). You may have to add extra empty columns in between your columns to get it just how you want it but it works great for me. Then just open your *.prn file in notepad and you are good to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.