+ Reply to Thread
Results 1 to 9 of 9

Sorting with vba

  1. #1
    Registered User
    Join Date
    06-30-2018
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    44

    Sorting with vba

    Hi

    I have a small problem with a script, as I recorded use to work but not anymore as I want it to.

    I have a sheet with data, rows from 2 to many over time. Each rows has a Kategory and I want to copy all these rows to a news sheet, but I want them to be sortet in som kind of header.

    If you look at my workbook, I want data from sheet1 to be placed in sheet"Backup" but sortet and and only listed ones below the header of the category each item have. I have tried the below code without any luck now.

    Also the code are under the 3 button on the first sheet and I hope someone could assist me?

    Sheets("Sheet2").Select
    UsedRange.Clear
    With [Sheet1!A1].CurrentRegion.Rows
    .Columns(7).AdvancedFilter 2, , .Range("K1"), True
    V = .Range("K1").CurrentRegion.Value2
    For L = 2 To UBound(V)
    .Range("K2").Value2 = V(L, 1)
    .AdvancedFilter 1, .Range("K1:K2")
    .Item("2:" & .Count).Columns("A:D").Copy Cells(R + 2, 1)
    With Cells(R + 1, 2)
    .Font.Bold = True
    .HorizontalAlignment = xlCenter
    .Value2 = V(L, 1)
    R = .End(xlDown)(2).Row
    End With
    Next
    .Parent.ShowAllData
    .Range("K1").CurrentRegion.Clear
    End With
    Attached Files Attached Files
    Last edited by Vibov; 05-13-2022 at 03:43 AM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Sorting with vba

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    06-30-2018
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    44

    Re: Sorting with vba

    Hi Jindon

    Thanks for taking the time for helping me out on this one. Unfortunal your code do the same as mine. I want the list to be like below on the Backup sheet and right now it list all the list for each kategory?



    A
    987 Peter 1 3,00 kr. A
    11 dwvvwrr 12 4,00 kr. A

    B
    12 dfg 4 7.876,00 kr. B

    D
    12 dfg 4 7.876,00 kr. D

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Sorting with vba

    Upload a workbook with EXACT result that you want, not the result that you don't want!!!

  5. #5
    Registered User
    Join Date
    06-30-2018
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    44

    Re: Sorting with vba

    Attachd the workbook with the backup sheet as I want it to look
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Sorting with vba

    So this is the EXACT result that you want...
    I will never work with a sample workbook with VBE locked any more.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    06-30-2018
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    44

    Cool Re: Sorting with vba

    Thanks i worked perfect :-)
    Attached Files Attached Files
    Last edited by Vibov; 05-13-2022 at 03:39 AM. Reason: Working perfect, thanks

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Sorting with vba

    Because you have nothing in "Kategori".

  9. #9
    Registered User
    Join Date
    06-30-2018
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    44

    Re: Sorting with vba

    Yes, thanks Jindon I just saw this and in the future IŽll upload the workbook without protection.
    Once again thanks alot for you help and time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] 3-level sorting including sorting a column by the number of percent sign in each cell
    By terryhenderson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-14-2017, 05:21 PM
  2. Replies: 1
    Last Post: 12-16-2015, 01:04 PM
  3. [SOLVED] I require sorting formula in excel sheet with complex sorting.
    By kaminanirav in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-24-2015, 08:16 AM
  4. Replies: 0
    Last Post: 02-24-2014, 11:27 AM
  5. Sorting 2 data ranges by comparing one column in each and sorting to match
    By MDKsmiffy in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-17-2013, 03:30 PM
  6. Sorting a range to invert it upside down without sorting by any specific column
    By luv2glyd in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-29-2013, 12:53 PM
  7. [SOLVED] Sorting a range to invert it upside down without sorting by any specific column
    By luv2glyd in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-28-2013, 12:43 PM

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