+ Reply to Thread
Results 1 to 6 of 6

Inserting cells to the left based on cell value

  1. #1
    Registered User
    Join Date
    02-23-2011
    Location
    Dallas
    MS-Off Ver
    Excel 2010
    Posts
    5

    Inserting cells to the left based on cell value

    Hi All,
    well my post from yesterday was answered quickly (THANKS Pike) but I noticed a quirk in my data sets that necessitates some additional coding.
    I have multiple test results (as CSV text files) in a directory that I can now import at the push of a button, but I noticed that some of the test results have an additional 16 columns of data in (they have 4 channels tested not just 2). Upshot is that during the test import, I need to see if the value of the field (always column "AP") reads as "Line3-DCVoltage3", ( this unit has the extra lines being tested), if this is true then I need to insert 16 blank cells (to the right of course) before the next cell is imported (would now be "BF")

    Or to put it another way, if "AP" = "Line3-DCVoltage3", then skip to column "BF" and continue with the text import, else do nothing .

    Code currently reads as follows:

    Please Login or Register  to view this content.
    Thanks for your help

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Inserting cells to the left based on cell value

    Hi Judge Dredd,
    The code you are using just imports. It doesnt read the txt line to determine any values.
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Registered User
    Join Date
    02-23-2011
    Location
    Dallas
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Inserting cells to the left based on cell value

    Thanks Pike,
    I understand that now. So would the correct way to be to insert a If / then statement inside the loop to check the value as it is being imported (something like:-)
    Please Login or Register  to view this content.
    or let the import finish, then loop through the data, look in column AP for the value, and execute a shift on the criteria being met. I would think the code above would also be something like what I need but it be preceeded by commands to find the data. Something like:
    Please Login or Register  to view this content.
    I tried this and it does find the text and inserts cells, but it inserts columns regardless of the cell value, so I assume that my use of the "If ActiveCell.Value...." is incorrect.
    Thanks
    Last edited by pike; 02-25-2011 at 06:46 PM. Reason: add / to code tags

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Inserting cells to the left based on cell value

    Hi
    You would need to use a different import code to read each cell value in csv and
    then you could use something like if the line value <> Line3-DCVoltage3

    would be better to cut and paste value the shift the columns

    can you post the different csv files

  5. #5
    Registered User
    Join Date
    02-23-2011
    Location
    Dallas
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Inserting cells to the left based on cell value

    Sure can, attached are a couple of the csv files, one with 2 test channels and one with 4.
    When I run the code, the first part brings in the text just fine.
    Please Login or Register  to view this content.
    The second part of the code is meant to search through and find the text "MocaTxBitRate" in column AP, and if true, insert 16 blank columns. Unfortunately it seems to insert 16 columns regardless of the conditions. So I know that the insert part works, the only issue seems to be not inserting if the condition is false. There is also probably a better way than just repeating the command 16 times, this seems a bit of a brute force method.

    Please Login or Register  to view this content.
    Thanks again, you have been a huge help. Excelforum is indeed the only place to go for help.
    Attached Files Attached Files

  6. #6
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Inserting cells to the left based on cell value

    Hi Judge Dredd,
    Apologies for the delay as ive been away for a week or so,

    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)

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