Results 1 to 6 of 6

VBA search for value and insert space two characters to the right

Threaded View

  1. #1
    Registered User
    Join Date
    12-08-2010
    Location
    Hamburg
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA search for value and insert space two characters to the right

    VBA search for value and insert space two characters to the right

    First of all a friendly hallo to all Forum members.

    Ok I've got about 20000+ lines of data that look like this:

    NODE S1 S2 S3 SINT SEQV
    1 -0.90520E-02-1.3410 -2.1393 2.1302 1.8640
    2 0.77851E-02-0.92696 -1.9901 1.9979 1.7314
    3 -0.34783E-01-1.1249 -2.0717 2.0370 1.7655
    4 0.36477E-01-0.93091 -2.0064 2.0429 1.7700
    5 0.83489E-02-0.92708 -1.9901 1.9985 1.7319

    And I want to insert a space behind "E-XX" so it will look something like this:

    NODE S1 S2 S3 SINT SEQV
    1 -0.90520E-02 -1.3410 -2.1393 2.1302 1.8640
    2 0.77851E-02 -0.92696 -1.9901 1.9979 1.7314
    3 -0.34783E-01 -1.1249 -2.0717 2.0370 1.7655
    4 0.36477E-01 -0.93091 -2.0064 2.0429 1.7700
    5 0.83489E-02 -0.92708 -1.9901 1.9985 1.7319

    At the moment the VBA code looks somewhat like this:

    No = 20000
    
    For i = 1 To No
    
       Ra = "A" & i
       Range(Ra).Select
    
    ActiveCell.Replace What:="E-01", Replacement:="E-01 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-02", Replacement:="E-02 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-03", Replacement:="E-03 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-04", Replacement:="E-04 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-05", Replacement:="E-05 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-06", Replacement:="E-06 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-07", Replacement:="E-07 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-08", Replacement:="E-08 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    ActiveCell.Replace What:="E-09", Replacement:="E-09 ", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False
    But unfortunately it has two major drawbacks. It is inefficient and thus quite slow and I have to edit the code every time I apply it to a new set of data depending on the number of lines.
    So my ides for improvement are the following.

    Find "E-" and insert a " " (space) two characters to the right of "E-"

    and

    No=(value in a specified cell)

    Unfortunately my web based research hasn't been to successful and all problems I found that were similar to mine were solved with code that is way out of my novas league.

    Any suggestions or help?

    Thank you for your time!

    the TUGuys
    Last edited by TUGuys; 12-09-2010 at 01:44 PM. Reason: violation of Forum rules

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