Reference changes in a macro or VBA

JohnJay

New Member
Joined
Mar 7, 2002
Messages
37
I am writing macros & VBA functions to do various tasks. But I wish to have cell references in the macros & VBA functions to be updates when a column or row is added to a sheet. Can anyone shed light on this?

Thank you
 
Barrie,

IT does not like the Range(Cells(1, SortColumn))

I was thinking along the lines of

Key1:=Range(Chr(65 + SortColumn) & "2")

But that will only work if "Divison" is between A & Z
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
On 2002-03-08 12:31, JohnJay wrote:
Barrie,

IT does not like the Range(Cells(1, SortColumn))

I was thinking along the lines of

Key1:=Range(Chr(65 + SortColumn) & "2")

But that will only work if "Divison" is between A & Z

John, I really must apologize for not testing this properly (I know, haste makes waste). How about:

Code:
Sub SortData()
Dim SortColumn As Integer, LastColumn As Integer
Dim LastRow As Long
LastColumn = Range("A1").End(xlToRight).Column
LastRow = Range("A65536").End(xlUp).Row
On Error GoTo ErrorHandler
SortColumn = Rows("1:1").Find(What:="Division", _
    LookAt:=xlWhole).Column
On Error GoTo 0
Range(Cells(1, 1), Cells(LastRow, LastColumn)).Sort _
    Key1:=Range(Cells(1, SortColumn).Address(False, False)), _
    Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, _
    Orientation:=xlTopToBottom
Exit Sub
ErrorHandler:
    MsgBox prompt:="Could not find a header labelled DIVISION" _
        & Chr(13) & "Data was not sorted", _
        Buttons:=vbCritical + vbOKOnly
End Sub

Let's hope I've finally got this pesky thing right :oops:
 
Upvote 0
Barrie,

your a genius...thank you very much. Many blessing to you. If I can pick your brain for something else, how are you on the rank function?
 
Upvote 0
On 2002-03-08 12:59, JohnJay wrote:
Barrie,

your a genius...thank you very much. Many blessing to you. If I can pick your brain for something else, how are you on the rank function?
I am familiar with it (although I wouldn't want to hazard a guess as to the extent of my familiarity). What do you want to know?
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,222
Members
448,951
Latest member
jennlynn

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