View Poll Results: Does it Work?

Voters
0. This poll is closed
  • Efficiently

    0 0%
  • Accurately

    0 0%
  • Short Code

    0 0%
Results 1 to 9 of 9

Code to Insert Column causes Macro to not function correctly...

Threaded View

  1. #1
    Registered User
    Join Date
    01-27-2012
    Location
    Phoenix, Arizona
    MS-Off Ver
    Excel 2010
    Posts
    6

    Question Code to Insert Column causes Macro to not function correctly...

    Trying to create a macro to delete rows based on contents of a column, complete a few sorts, add a column and then combine contents of 3 columns into 1 for each row respectively and then subtotal based on the new combined column.

    Here is what I have that works but once I try to add column, macro does not complete the sorts at all or incorrectly depending on where the code for the insertion is placed and the code is edited based on placement of the code to insert the column.

    Sub Delete()
        Range("A4:J992").Select
        Range("F4:F996").Replace 0, "", xlWhole
        Range("F4:F996").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End Sub
    Sub Sort2()
        Range("A4:J996").Select
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Clear
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("C4:C996"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("D4:D996"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort.SortFields.Add Key:=Range("E4:E996"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets(ActiveSheet.Name).Sort
        .SetRange Range("A4:K996")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
        End With
    End Sub
    Insertion Code...

    Sub InsertColumn()
        Columns("C:C").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    End Sub
    Also can not get the concatenate or =D1&" "&E1&" "&F1 to fill the new C column...the formula works for the first cell and looks correct, meaning row number within formula changes, for the next cells but the outcome is the value of the first cell C1...

    Help???
    Last edited by numbersbuff; 01-27-2012 at 04:20 PM. Reason: Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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