Question on VBA Script
Closed
dumow880
Posts
7
Registration date
Thursday July 7, 2011
Status
Member
Last seen
July 17, 2012
-
Jul 17, 2012 at 05:10 PM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Sep 15, 2012 at 07:35 AM
rizvisa1 Posts 4478 Registration date Thursday January 28, 2010 Status Contributor Last seen May 5, 2022 - Sep 15, 2012 at 07:35 AM
Related:
- Question on VBA Script
- Vba case like - Guide
- Excel online vba - Guide
- Ubuntu startup script - Guide
- Vba timer - Guide
- Vba excel mac - Guide
Sep 15, 2012 at 07:35 AM
Function Custom() 'start from cell A100000 and get the last cell that is above a blank cell ' basically an attempt to find out the last cell (not the best way i would say) FindLastRow = Range("A100000").End(xlUp).Row 'select the first sheet (first sheet is subjective and again not best way) Sheets(1).Select 'on the selected sheet, select cell A1 Range("A1").Select 'select the curretnly used cells starting from A1 Selection.CurrentRegion.Select 'sort of column A ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A1:A" & FindLastRow), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Sheet1").Sort .SetRange Range("A1:A" & FindLastRow) .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With 'select the 2nd sheet (2nd sheet is subjective and again not best way) Sheets(2).Select ' as before from here FindLastRowSort = Range("A100000").End(xlUp).Row Range("A1").Select Selection.CurrentRegion.Select ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("B1:B" & FindLastRowSort), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Sheet2").Sort .SetRange Range("A1:B" & FindLastRowSort) .Header = xlGuess .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With End Function