+ Reply to Thread
Results 1 to 9 of 9

Sort Column, Delete Rows, Delete Column, Move Molumn, more inside?

  1. #1
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Sort Column, Delete Rows, Delete Column, Move Molumn, more inside?

    Looking for a macro that will go though a file similar to what is attached (attached is just much smaller scale xls file) and perform the following. Everything is on one sheet. The file this will be used in will start as, and remain a CSV file. Will that cause any problems? I have one built that deleted the row based on case criteria, but adding in the other items and actually deleteing the rows, not just the cell data, is more of what I'm looking for.

    -

    Sort By Serial Number

    Delete all non check lines (lines with no data, or simply that doesn't match serial number pattern would be best)

    Insert a column A

    Insert a column call Type after serial number Description

    Move description to end and delete data (starts in row 2)

    Delete CR/DR column

    Save and prompt to change name (not really needed)
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You could make a start by using the macro recorder to get the basic code for adding a column, sorting etc.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    08-23-2007
    Location
    Nanaimo, BC, Canada
    Posts
    12
    Hi motown.

    Here's a first attempt base don your descriptions
    Attached Files Attached Files
    http://www.excelvba.joellerabu.com

  4. #4
    Registered User
    Join Date
    03-25-2008
    Posts
    71
    That works perfectly except for one small little detail. The "Description" Column C in the orignial doc ends up deleted, but should be move to follow the new "Type" column.

  5. #5
    Registered User
    Join Date
    03-25-2008
    Posts
    71
    n/m, I needed the column goen anyway.

  6. #6
    Registered User
    Join Date
    08-23-2007
    Location
    Nanaimo, BC, Canada
    Posts
    12
    Hi Motown,

    Small bug in code. If there was no data in Col D it was deleting the header row. This adapted line will fix that.


    [vba]
    Option Explicit

    Sub AsRequested()

    Dim fName As String
    Dim LastRow As Long

    Application.ScreenUpdating = False

    Columns("A:A").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
    Columns("A:A").Insert Shift:=xlToRight
    Columns("E:E").Delete Shift:=xlToLeft
    Columns("D:D").Insert Shift:=xlToRight
    Range("D1") = "Type"

    LastRow = Range("E65536").End(xlUp).Row


    '//Adapted line
    If LastRow > 1 Then
    Range("E2:E" & LastRow).ClearContents
    End If
    '//


    fName = InputBox("Enter filename to save as", "Filename?")

    'ActiveWorkbook.SaveAs FileName:=fName, FileFormat:= _
    xlNormal, Password:="", WriteResPassword:="", _
    ReadOnlyRecommended:=False _
    , CreateBackup:=False

    Application.ScreenUpdating = True

    End Sub
    [/vba]

  7. #7
    Registered User
    Join Date
    03-25-2008
    Posts
    71

    Thumbs up

    Thanks a TON rbrhodes!

    They changed things up on me a bit, and I think this is for the better as I actually have the actual file in hand and not what they "think" will be used. I have the "start" file with the base and the needs in the comments. And then I've added an "end" file with that they are looking to be the final product.

    Does this help?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    08-23-2007
    Location
    Nanaimo, BC, Canada
    Posts
    12
    Take a look!
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-25-2008
    Posts
    71
    Perfect!!

    And the more I see these set up the more I start to understand the them.

+ 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