Results 1 to 6 of 6

Remove unnecessary code in macro

Threaded View

  1. #1
    Registered User
    Join Date
    03-17-2013
    Location
    Australia
    MS-Off Ver
    Excel 2007
    Posts
    13

    Remove unnecessary code in macro

    Hi
    I'll start by saying I'm very new to all this and I'm learning a lots as I go.

    I have multiple lots of data that is in two columns. The left with a timestamp that I need to convert to an excel format and the other just values relevant to the timestamp.

    My macro was developed with help here
    http://www.excelforum.com/excel-prog...-relative.html

    It converts both columns to a date format. I'd like only the column that contains dates to do so.

    Sub Timestamp()
    '
    ' Timestamp Macro
    '
    ' Keyboard Shortcut: Ctrl+t
    
        ActiveCell.CurrentRegion.NumberFormat = "d/m/yyyy h:mm"
        ActiveCell.CurrentRegion.Offset(0, 2).Resize(, 1) = "=LEFT(RC[-2],10)+(MID(RC[-2],12,8))"
    
    End Sub
    I think I have fixed it though probably not in the most elegant of ways.
    I modified the macro slightly and I thinks its much better now copying and putting the excel dates back on top of the original timestamps and fixing the value column. I'm not sure its the simplest and neatest it could be and I was wondering if there is any irrelevant code I could remove. Am I correct in saying the blue bit can go?
    Sub Timestamp()
    
    ' Timestamp Macro
    '
    ' Keyboard Shortcut: Ctrl+t
    
        ActiveCell.CurrentRegion.NumberFormat = "d/m/yyyy h:mm"
        ActiveCell.CurrentRegion.Offset(0, 2).Resize(, 1) = "=LEFT(RC[-2],10)+(MID(RC[-2],12,8))"
        
        Range(Selection, Selection.End(xlDown)).Select
        Selection.Copy
        ActiveCell.Offset(0, -2).Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
             xlNone, SkipBlanks:=False, Transpose:=False
        ActiveCell.Offset(0, 2).Range("A1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-12
        ActiveCell.Offset(0, -1).Range("A1").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.NumberFormat = "0.00"
    End Sub
    cheers rileyp
    Last edited by rileyp; 04-03-2013 at 03:42 AM.

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