Paste formatted SQL queries from text file into Excel (one Excel row for each query)

Blue1971

New Member
Joined
May 19, 2020
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
I have a .TXT text file that has formatted SQL queries in it.

SQL:
--The corresponding Excel row ID is: 2
select
    main.active_transportation.objectid,
    main.active_transportation.type,
    main.active_transportation_nt_flag_vw.objectid,
    main.active_transportation_nt_flag_vw.flag
from
    main.active_transportation
left outer join main.active_transportation_nt_flag_vw on
    main.active_transportation.objectid = main.active_transportation_nt_flag_vw.objectid
where
    main.active_transportation.objectid in ( 49996, 49997, 49998, ... );
--The corresponding Excel row ID is: 3
select
    main.active_transportation.objectid,
    main.active_transportation.type,
    main.active_transportation_nt_flag_vw.objectid,
    main.active_transportation_nt_flag_vw.flag
from
    main.active_transportation
left outer join main.active_transportation_nt_flag_vw on
    main.active_transportation.objectid = main.active_transportation_nt_flag_vw.objectid
where
    main.active_transportation.objectid in ( 14113, 14114, 14115, ... );
--The corresponding Excel row ID is: 4
select
    main.active_transportation.objectid,
    main.active_transportation_nt_flag_vw.flag
from
    main.active_transportation
left outer join main.active_transportation_nt_flag_vw on
    main.active_transportation.objectid = main.active_transportation_nt_flag_vw.objectid
where
    main.active_transportation.objectid in (54081, 54082, 54083, ...);

I want to copy the text from a text editor and paste it into Column D in an Excel 365 spreadsheet.

Each query would be inserted into it's own cell/row. Like this:

enter image description here

Regarding the SQL comments in each query:

SQL:
--The corresponding Excel row ID is: 2

It would be ideal if the SQL comments were removed. But it's ok to leave them in if it's too hard or messy to get rid of them.

It would also be ideal if the SQL spacing were visible -- without the need to double-click a cell to see the proper spacing. But again, that's not necessary if it's not practical.


How can I paste the formatted SQL queries into Excel? (one Excel row for each query)
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe this for the line wrapping part?
As for row/column sizes, selecting the column divider and double clicking it will size the width. Same for the row dividers when rows are selected.
As for the comments, not sure what would work. If you could find them based on green text (are they green in the results?) you run the risk of deleting text you want to keep. Also wondering if Instr function could find the line based on first finding -- then finding a line wrap and getting the length between those 2 points. Seems kind of dangerous though.
 
Upvote 0

Forum statistics

Threads
1,215,345
Messages
6,124,408
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top