I have been unsuccessful in both searching and experimenting with a macro that would do the following.

Given a .csv file, I want to create a macro that would:

  • Reference that file from a separate workbook
  • Choose a selected list of values within a column of data
  • Group those values in ascending order
  • Sort each these group's rows in ascending order by a different column within their rows.
  • Print this arranged data on a worksheet within the separate workbook.

for example: This image Initial Table

would be made into this image. Final Table

Note: These examples have been simplified as the rows contain many columns of data to be included.

  • 1
    Your question is too vague. Anyone could write a macro that satisfies your bullet points but would still be useless to you. Please include an example of your actual data format, the macro that you posted in the comment below, and your specific criteria. – picobit Sep 20 '16 at 15:17
  • Please include the things that you tried before you considered your attempts unsuccessful as mentioned in the question – thilina R Sep 23 '16 at 20:58
  • I didn't want to drag someone down my rabbit hole, though I've shared my best attempt, so that if I took the wrong path others wouldn't follow. Since you want to follow my path look at the macro I have shared. It works for one iteration but I can't do it for anymore. If I could get it to append 30 more itterarions of different referenced values I would have accomplished my task. If I share anything else it will have reached the point where I have figured it out myself and teaching others how to do it, which I'll do if that is the case. – Red Kong Sep 24 '16 at 14:31

Your problem description is too vague, but you can very easily turn your initial table into your final table by just using Excel's filtering functinon. You just have to sort it twice. First, sort column B ascending, and then sort column A ascending.

  • I am actually work with a .csv file that contains hundreds of serial numbers. Each serial number has rows of lab data pertaining. I am only interested in 31 of these serial numbers. Your description will not be very helpful compared to what I currently do. I currently this macro: – Red Kong Sep 20 '16 at 14:01
  • Sub Get_data_from_database() ' Keyboard Shortcut: Ctrl+d Dim ESN ESN = Range("tabname!B1") Workbooks.Open Filename:= _ "C:\filelocation\LubeAnalysisData_ky082.csv" Cells.Select Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Key2:=Range("L2") _ , Order2:=xlAscending, Header:=xlGuess, OrderCustom:=1, MatchCase:= _ False, Orientation:=xlTopToBottom, DataOption1:=xlSortTextAsNumbers, _ DataOption2:=xlSortNormal Columns("I:I").Select Selection.AutoFilter Selection.AutoFilter Field:=1, Criteria1:=ESN End Sub – Red Kong Sep 20 '16 at 14:01
  • Using this provides me one serial number's rows sorted in ascending order. I have to copy, paste, and continue doing this 30 more times to report our data. – Red Kong Sep 20 '16 at 14:05

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.