simple macro

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oli

    simple macro

    Hi

    I need a simple excel macro that searches the first 1000 rows, column A
    only, of the active worksheet and all text past the first space of each cell
    is copied into the B column. Any ideas?

    Cheers
    Oli


  • Norman Yuan

    #2
    Re: simple macro

    Following VBA code will do what you want:

    Sub PartialCopyAToB ()

    Dim strA As String
    Dim strB As String
    Dim sht As Excel.Worksheet

    Dim i As Integer
    Dim intSpace As Integer

    Set sht=ThisWorkboo k.ActiveSheet

    For i = 1 To 1000
    strA = sht.Cells(i, 1)
    intSpace = InStr(1, strA, " ")
    If intSpace > 0 Then
    strB = Mid(strA, intSpace + 1)
    Else
    strB = strA
    End If
    sht.Cells(i, 2) = strB
    Next

    End Sub

    HTH

    "Oli" <oli@NOSPAMoliw oods.co.uk> wrote in message
    news:btbvid$t8q [email protected] ernet.com...[color=blue]
    > Hi
    >
    > I need a simple excel macro that searches the first 1000 rows, column A
    > only, of the active worksheet and all text past the first space of each[/color]
    cell[color=blue]
    > is copied into the B column. Any ideas?
    >
    > Cheers
    > Oli
    >
    >[/color]


    Comment

    Working...