+ Reply to Thread
Results 1 to 3 of 3

Manipulating Strings

  1. #1
    Leslie Coover
    Guest

    Manipulating Strings

    The following code copies two characters from a string in worksheet 1
    and places them in a column to the right of where the string is. How would
    I write this code
    so I can place the code in worksheet 2 and it will get the characters from
    worksheet 1 and put them in a column in worksheet 2?

    Sub GetString()
    Dim MyString As String
    Dim Pick As String

    Cells(1, 1).Select
    Do While ActiveCell.Value <> ""
    MyString = ActiveCell
    Pick = Mid(MyString, 2858, 2)


    ActiveCell.Offset(0, 112) = Pick
    ActiveCell.Offset(1, 0).Select
    Loop
    End Sub

    Thanks,
    Les



  2. #2
    Forum Contributor
    Join Date
    03-03-2005
    Posts
    315
    Your code places the 2 characters in a column 112 places to the right of the activecell (and not adjacent to the activecell).

    Secondly, those 2 characters are extracted from strings comprised of 2,858 characters!

    You may wish to verify whether this is what you need to do.

    As to copying your extracts to worksheet2, see below bolded for effect.

    Sub GetString()
    Dim MyString As String
    Dim Pick As String

    Cells(1, 1).Select
    k = 1
    Do While ActiveCell.Value <> ""
    MyString = ActiveCell
    Pick = Mid(MyString, 2858, 2)
    Sheet2.Cells(k, 1) = Pick
    ActiveCell.Offset(1, 0).Select
    k = k + 1
    Loop
    End Sub

  3. #3
    Rowan
    Guest

    RE: Manipulating Strings

    Assuming you want the results in column DH on Sheet2 then:

    Sub GetString()
    Dim lRow As Long
    Dim cRow As Long
    Dim Sht1 As Worksheet
    Dim Sht2 As Worksheet
    Dim colA As Range
    Dim Cell As Range

    Set Sht1 = Sheets("Sheet1")
    Set Sht2 = Sheets("Sheet2")
    With Sht1
    lRow = .Cells(Rows.Count, 1).End(xlUp).Row
    Set colA = Range(.Cells(1, 1), Cells(lRow, 1))
    cRow = 1
    For Each Cell In colA
    Sht2.Cells(cRow, 112).Value = Mid(Cell.Value, 2858, 2)
    cRow = cRow + 1
    Next Cell
    End With
    End Sub

    Hope this helps
    Rowan

    "Leslie Coover" wrote:

    > The following code copies two characters from a string in worksheet 1
    > and places them in a column to the right of where the string is. How would
    > I write this code
    > so I can place the code in worksheet 2 and it will get the characters from
    > worksheet 1 and put them in a column in worksheet 2?
    >
    > Sub GetString()
    > Dim MyString As String
    > Dim Pick As String
    >
    > Cells(1, 1).Select
    > Do While ActiveCell.Value <> ""
    > MyString = ActiveCell
    > Pick = Mid(MyString, 2858, 2)
    >
    >
    > ActiveCell.Offset(0, 112) = Pick
    > ActiveCell.Offset(1, 0).Select
    > Loop
    > End Sub
    >
    > Thanks,
    > Les
    >
    >
    >


+ 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