I am having a heck of a time finding the last columns and rows. I know I'm missing something simple and I've gotten this far with some help (Thanks KD!) but I still can't find the missing link. I see and understand all the articles, but I'm missing something obvious.
I have the following but it's giving me an error. Compile error, expected array" lstRow = lastRow(ws, "J")
This is in Module 4 I tried using a personal excel macro workbook but that isn't working either.
This is in Module 3
How do I call functions? I'm sorry but I'm just not getting it. Thanks!!
I have the following but it's giving me an error. Compile error, expected array" lstRow = lastRow(ws, "J")
This is in Module 4 I tried using a personal excel macro workbook but that isn't working either.
Code:
Option Explicit
Public Function lastRow(ws As Worksheet, Optional col As Variant = 1) As Long
With ws
lastRow = .Cells(.Rows.Count, col).End(xlUp).Row
End With
End Function
Public Function LastColumn(ws As Worksheet, Optional rowNum As Long = 1)
With ws
LastColumn = .Cells(rowNum, .Columns.Count).End(xlToLeft).Column
End With
End Function
This is in Module 3
Code:
Sub Module3()
Doing some other things and then
Dim ws As Worksheet
Dim sortRng As Range, rngL As Range, rngJ As Range
Dim lstRow As Long
Set ws = ThisWorkbook.Worksheets("Sheet1")
lstRow = lastRow(ws, "J")
With ws
Set sortRng = .Range("B11", .Cells(lstRow, LastColumn(ws, 11)))
Set rngJ = .Range("J11:J" & lstRow)
Set rngL = .Range("L11:L" & lstRow)
With .Sort
.SortFields.Clear
.SortFields.Add Key:=rngJ, SortOn:=xlSortOnValues, Order:=xlAscending, _
CustomOrder:="AmEx,Discover,Master Card,Visa,Check", DataOption:=xlSortNormal
.SortFields.Add Key:=rngL, SortOn:=xlSortOnValues, Order:=xlDescending, _
DataOption:=xlSortNormal
.SetRange sortRng
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
How do I call functions? I'm sorry but I'm just not getting it. Thanks!!