Existing code over 4 columns need help

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,738
Office Version
  1. 2007
Platform
  1. Windows
Evening,

I thought i new what i was doing but ......

I have a range on one sheet as follows C1:F13 "split into 4 columns"
C = name D = total sold "C1:D13"
E = name F = total sold "E1:F13"

Clicking on a button would copy info from range above "C1:D13" & "E1:F13" then sort from popular to least popular on another sheet in the range C1:D26

I need to sort these items BUT on the same sheet now.
Basically the range of names / items sold just need to be sorted in the same range each time my button is pressed.

If any help to you the existing working code is shown below,"this copies from one sheet & sorts & thes pastes on another sheet"

Code:
Sub LEADERBOARD()    '' leaderboard Macro'    Worksheets("HONDA SHEET").Range("C1:D13").Copy Worksheets("SOLD ITEMS").Range("C1:D14")
    Worksheets("HONDA SHEET").Range("E1:F13").Copy Worksheets("SOLD ITEMS").Range("C14:D26")


    ActiveWorkbook.Worksheets("SOLD ITEMS").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("SOLD ITEMS").Sort.SortFields.Add Key:=Range("D1"), _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortTextAsNumbers
    With Worksheets("SOLD ITEMS").Sort
        .SetRange Range("C1:D26")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


    With Worksheets("SOLD ITEMS").Range("C1:D26").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        End With
    Application.Goto Sheets("SOLD ITEMS").Range("A4")
End Sub
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi,
Ive got to use the code so far shown below.

My problem is the splitting / pasting of the results.
C1:D13 sorts fine where E1:F!3 has no affect,this is where my problem lies,two columns would be fine for me but space is limited hence splitting over 4 columns.


Code:
Sub LEADERBOARD()    '' leaderboard Macro'    Worksheets("HONDA SHEET").Range("C1:D13").Copy Worksheets("SOLD ITEMS").Range("C1:D13")
    Worksheets("HONDA SHEET").Range("E1:F13").Copy Worksheets("SOLD ITEMS").Range("E1:F13")


    ActiveWorkbook.Worksheets("HONDA SHEET").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("HONDA SHEET").Sort.SortFields.Add Key:=Range("D1"), _
    SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
    xlSortTextAsNumbers
    With Worksheets("HONDA SHEET").Sort
        .SetRange Range("C1:F13")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With


    With Worksheets("HONDA SHEET").Range("C1:F13").Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        End With
    Application.Goto Sheets("HONDA SHEET").Range("A13")
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top