+ Reply to Thread
Results 1 to 7 of 7

Delete rows beginning with !, Add new first row.

  1. #1
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Delete rows beginning with !, Add new first row.

    Hello,

    I am trying to make a complex spreadsheet that will import .s2p files (just text files with a different extension) containing some data, each to a different sheet, delete the beginning comment rows, add a row that has headings describing the data.

    All of that for the raw data files (between 1 and ~30 files), a reference file, and an ideal file. I then want to so math on each of the data files with the reference file. After all that I need to do math on the new data with regards to the ideal file and make plots.

    I have gotten as far as importing the -space- delimited .s2p files by copying and editing code I've found on the internet. I need help deleting the comment rows (all the first rows that begin with ! can be anywhere from 0 to 12 from what I've seen, and possibly more, as there is no practical limit) and adding a row with headings (instead of leaving a row and overwriting the cells, causing a text box that warns that there is already data here).

    Any other suggestions about how I butchered the code together and/or any improvements I could make is also welcome.

    Please Login or Register  to view this content.
    Here is an example of how an .s2p file looks, the formatting is the same (with the first column denoting the frequency, then 8 columns of data following), but the data can go on indefinitely, and there can be any number of comments at the top. It is just a text file with .s2p as the extenstion.

    Please Login or Register  to view this content.
    p.s. I assume it would be better to break up any further questions into new posts as opposed to adding to this one, please confirm.

    Posted question to MrExcel as well.
    Last edited by spencer_time; 09-24-2019 at 04:57 PM. Reason: Stated that I posted question to another forum

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: Delete rows beginning with !, Add new first row.

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.


    As you have less than 5 posts I will do it for you
    https://www.mrexcel.com/forum/search...rchid=10225797

  3. #3
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Re: Delete rows beginning with !, Add new first row.

    I'm sorry if I misunderstood, but I read the rules, and even edited my post to mention that I posted the question on another forum as soon as I made the second post.
    3. Questions that are cross-posted to other web forums must contain links to those posts on those forums or a comment to tell us where else the question has been asked. (A, Z*)
    But the rules also stated not to post links to competing forums, so I said the name of where I posted it instead.
    10. Do not put links to commercial sites or services or to competing forums in signatures and posts. (A, B)
    The rules I quoted came from the forum rules page found at this website with the following after the .com /forum-rules/642590-forum-rules.html sorry, I would have posted a link to show you, but I cannot post links, I'm guessing because I don't have enough posts yet. Which also brings up a second point I was unaware of, if I cannot post links, how would I post a link to another forum even if I was mistaken.

    If I read the rules incorrectly, perhaps they could be edited to be made more clear to avoid this type of situation with new users in the future.

    After that whole explanation, it comes down to one thing. Do you want me to post a direct link to my question if I post it in a competing forum in the future? If that is the case, how many post must I have in order to post a link? I will do my best to get to that point.

    -Trent Spencer - KM4YTU

  4. #4
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Re: Delete rows beginning with !, Add new first row.

    Some progress has been made on this problem by user Fluff at the MrExcel forums. I swapped out a section of my code for his suggestion, replacing the two sections that delete rows that start with ! and add a row with headings.

    The new code seems to delete the rows with comments beginning with ! just as expected (regardless of what s2p file I load), however when inserting a row with headings I get an error stating that there is already data there (only on s2p files that did not have rows with comments at the top of the file), and asking me if I would like to replace it.

    Adding to the issue, while testing the new code with other .s2p files (files without the !comments at the top) I found that the delimiting of the data does not always work as expected, and produces a completely different outcome. I noticed that when viewing the file without !comments in a text editor such as Notepad++ that the columns of data do not line up exactly. This appears to be due to the addition of the "-" for negatives, as well as leading and trailing zeros causing issues. I suspect that the data being formatted this way is the reason for the delimiting problems I am now having to some files.

    Attached below is the new code, with the changes Fluff suggested added to it. Also attached is a screenshot of how the delimiting is broken with some files.

    Please Login or Register  to view this content.
    Sorry, I cannot upload a screenshot until I have more posts, however I will describe the problem as best I can.

    The first row (1) is correct [it does produce the error I mention however]. The first column (A) is correct. The last four columns (H:K) are correct. However the second through seventh columns (B:G) [with the exception of row 1 from those columns] are empty, with the data that was supposed to be in them apparently deleted.

    Any suggestions are welcome.

    EDIT: I mention the progress from the other forum in order to stop someone else from working on an aspect of the problem that has already been solved.

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: Delete rows beginning with !, Add new first row.

    Quote Originally Posted by spencer_time View Post

    After that whole explanation, it comes down to one thing. Do you want me to post a direct link to my question if I post it in a competing forum in the future? If that is the case, how many post must I have in order to post a link? I will do my best to get to that point.

    -Trent Spencer - KM4YTU
    By all means post a link to ALL your cross posts. The link provided in post #2 explains why this is necessary and you will certainly understand that these reasons precede any others out of respect for those helping you.
    As you now have 5 posts you can add links as the last sentence in post #2 indicates indirectly.

  6. #6
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Re: Delete rows beginning with !, Add new first row.

    I was under the impression that I didn't need to as you said that you did it for me because I had less than 5 posts. But since I can post links now, and in order to comply with the rules after your clarification I will also include it.

    I have asked this question *here* at Excel Forum on Tuesday 09/24/2019 at 13:19 CST
    excelforum with this after com /excel-programming-vba-macros/1290901-delete-rows-beginning-with-add-new-first-row.html

    I also asked the same question in one other forum, Mr Excel, a few hours later on the same Tuesday 09/24/2019 at 15:54 CST
    mrexcel with this after com /forum/excel-questions/1110666-delete-rows-beginning-insert-row-text-into-multiple-sheets.html

    Well, I tried to and still cant post links, so I left the link in and "broke" it by removing the protocol and domain, I hope that is okay.
    At this point I feel like I need to prove myself, so here is a [broken] link to a screenshot showing me being denied posting a post containing a link.
    drive.google with this after com /uc?id=1UtCeVgl3z-2hVuXna-EO_i5CJV21LcE9

  7. #7
    Registered User
    Join Date
    08-27-2019
    Location
    Alabama, USA
    MS-Off Ver
    365, 2016, 2010, 2007
    Posts
    57

    Re: Delete rows beginning with !, Add new first row.

    This problem was solved by user Fluff on the MrExcel forum's at the following link with the following code.

    mrexcel dot com /forum/excel-questions/1110666-delete-rows-beginning-insert-row-text-into-multiple-sheets-post5347700.html#post5347700

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Delete rows in sheet that contain same name of imported worksheets
    By gxsgeorgie in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-15-2017, 02:41 PM
  2. Replies: 0
    Last Post: 03-29-2017, 09:33 PM
  3. Edit/Delete data rows using VBA / Userform
    By BigPaulMc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2015, 05:17 PM
  4. [SOLVED] Formula (not vba) to delete row if cell blank on imported data
    By NeilAZ in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-05-2013, 02:37 AM
  5. Add, delete & edit rows automatically
    By Baziwan in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-14-2012, 08:25 AM
  6. how to delete imported data from sheet in VBA
    By bgbainbridge in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-26-2011, 03:29 PM
  7. [SOLVED] Delete rows not in Edit Menu
    By NewsgroupFan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-26-2005, 09:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1