Consulting

Results 1 to 8 of 8

Thread: Solved: 4 letters

  1. #1
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location

    Solved: 4 letters

    hi
    i need a help with a macro that will 4 first letters in the
    cell in column "b" and the rest will be deleted

    thanks

  2. #2
    VBAX Regular kroz's Avatar
    Joined
    Sep 2010
    Posts
    74
    Location
    I feel like i'm mindreading here..
    Do you by any chance want a macro that would take only the first 4 letters of the string in column B?

    [vba]
    range("B1").value = left(range("B1").value,4)
    [/vba]

  3. #3
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    hi
    the cell needs to remane with 4 leters only
    the rest should be deleted

    thnks

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Public Sub ProcessData()
    Const TEST_COLUMN As String = "B" '<<<< change to suit
    Dim Lastrow As Long
    Dim i As Long

    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    For i = 1 To Lastrow

    .Cells(i, TEST_COLUMN).Value2 = Left$(.Cells(i, TEST_COLUMN).Value2, 4)
    Next i
    End With

    Application.ScreenUpdating = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Hi
    thanks for the replay it all works ok
    i just have one question why is it taking so long to qalqulate 1000 rows?

    thanks

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Have you got formulae on that sheet?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    VBAX Contributor
    Joined
    May 2010
    Location
    Sydney, NSW, Australia
    Posts
    170
    Location
    Try turning calculation off whilst it does its thing:

    [vba]
    Public Sub ProcessData()
    Const TEST_COLUMN As String = "B" '<<<< change to suit
    Dim Lastrow As Long
    Dim i As Long

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False

    With ActiveSheet

    Lastrow = .Cells(.Rows.Count, TEST_COLUMN).End(xlUp).Row
    For i = 1 To Lastrow

    .Cells(i, TEST_COLUMN).Value2 = Left$(.Cells(i, TEST_COLUMN).Value2, 4)
    Next i
    End With

    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True
    End Sub
    [/vba]

  8. #8
    VBAX Tutor
    Joined
    Dec 2009
    Posts
    295
    Location
    Great thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •