Consulting

Results 1 to 4 of 4

Thread: Date format

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location

    Date format

    Hello,

    I want to make my excel column in a date format.

    the following are my code, but i not too sure where i go wrong.
    The output only format one cell and not the whole column.

    Sub Identify_TxnGrouping()
    Dim i As Integer, lastfoundrow
        Range("A1").Select
        Columns("A:B").Select
        'Selection.Insert Shift:=xlToRight
        Selection.EntireColumn.Insert
     
     
        lastfoundrow = 0
        Range("A1").Select
        Do While ActiveCell.Row <= lastrow
            i = 0
            XLFind "TC=000", "Part"
            If Not blnfound Then
                Exit Do
            End If
            If ActiveCell.Row < lastfoundrow Then
                Exit Do
            End If
                   'getting the file date
            i = InStr(1, ActiveCell.Offset(-8, 0).Value, "FILE DATE", vbTextCompare)
            If i > 0 Then
                ActiveCell.Offset(1, -1).Value = Format _
    (Mid(ActiveCell.Offset(-8, 0).Value, i + 10, 10), "dd-mmm-yyyy")
                ActiveCell.Offset(1, -1).NumberFormat = "dd-mm-yyyy"
            End If
     
            'ActiveCell.Offset(-1, 0).Select
            x = ActiveCell.Offset(-5, 0).Row
            y = ActiveCell.Row
            If x >= Range("lastdatarow").Row Or y >= Range("lastdatarow").Row Then
                ActiveCell.Offset(1, 0).Name = "LastDataRow"
            End If
            Range(ActiveCell.Offset(-5, 0).Cells, ActiveCell.Cells).Select
            Selection.EntireRow.Delete
            lastfoundrow = ActiveCell.Row
            lastrow = Range("LastDataRow").Row
        Loop
        lastrow = Range("LastDataRow").Row
     
    End Sub
    Thanks!

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    It's because you are only working with the activecell and the activecell doesn't move!, you are not progressing through cells in your code, A1 is always your activecell so you are only formatting the offsets with relation to it.
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I haven't looked in detail at the code, but you seem to have commented out the one line that moves the activecell, but seeing as it moves it up a row, and you start in row 1, that probab ly caused you a problem.
    ____________________________________________
    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

  4. #4
    VBAX Regular
    Joined
    Jun 2008
    Posts
    22
    Location
    okay. thanks.
    now that i know the problem, i can solve it. thanks a lot!

Posting Permissions

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