Macro to perform 2 tasks

nparsons75

Well-known Member
Joined
Sep 23, 2013
Messages
1,254
Office Version
  1. 2016
Hi,

I have a range of cells that contain data. B12:K44

I need a macro that when activated performs the following tasks.

Each column to be sorted alphabetically in ascending order.
Any BLANK cells below the NON BLANK cells will be populated with the text 'AVAILABLE'

Hoping someone can assist, thank you in advance.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try this on for size

Code:
Sub Macro2Perform2Tasks()
Dim lrow, i, j As Long


lrow = ActiveSheet.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
    
    For i = 2 To 11
    
        Worksheets(1).Sort.SortFields.Clear
        Worksheets(1).Sort.SortFields.Add Key:=Cells(1, i), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
        xlSortTextAsNumbers
        With ActiveWorkbook.Worksheets(1).Sort
        .SetRange Range(Cells(2, i), Cells(lrow, i))
        .Header = xlNo
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
        End With
            
            For j = lrow To 2 Step -1
                If Cells(j, i) = "" Then
                    Cells(j, i) = "AVAILABLE"
                End If
            Next j
        
   Next i
   
   
   
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,904
Members
449,477
Latest member
panjongshing

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