+ Reply to Thread
Results 1 to 5 of 5

Excel VBA Help

  1. #1
    Registered User
    Join Date
    10-26-2006
    Posts
    26

    Excel VBA Help

    Hello, I am hoping that someone can help me with a VBA solution to my problem. I am trying to create a script that would loop through an excel spreadsheet and fill in the information needed.

    What I am trying to accomplish is this.

    For every cell that has a length of 9 remember the first 6 characters and if the next cell has a length of 3, paste the remembered characters at the beginning of the string and move on to the next cell. I have pasted an example.

    Cell Format Desired Format
    123456ABC 123456ABC
    DEF 123456DEF
    GHI 123456GHI
    7890123TR 7890123TR
    FVD 7890123FVD
    DCW 7890123DCW
    EDC 7890123EDC
    WQA 7890123WQA
    QWS 7890123QWS


    Any suggestions?
    Thanks in advance for your help.

  2. #2
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi

    Would this help?
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    If you have data in column 'A' from row 1 you can use this code:

       lastRow = Range("a65536").End(xlUp).Row

       textToRemember = ""
       For r = 1 To lastRow
          myText = Cells(r, 1).Value
          If Len(myText) = 9 Then
             textToRemember = Left(myText, 6)
             Cells(r, 2) = myText
          Else
             Cells(r, 2) = textToRemember & myText
          End If
       Next

    Regards,
    Antonio

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    I excuse for the format of previous code:

    lastRow = Range("a65536").End(xlUp).Row

    textToRemember = ""
    For r = 1 To lastRow
    myText = Cells(r, 1).Value
    If Len(myText) = 9 Then
    textToRemember = Left(myText, 6)
    Cells(r, 2) = myText
    Else
    Cells(r, 2) = textToRemember & myText
    End If
    Next

  5. #5
    Registered User
    Join Date
    10-26-2006
    Posts
    26

    Thanks

    Thanks you guys!!!! Both worked. You Rock!

+ 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