Macros to autosort dates in column B

NANSAL0222

New Member
Joined
May 29, 2019
Messages
1
I am getting a code break error in my formula - I need to auto sort wit a command key by column B but have all my columns pull into the sort - through column M. This is my first attempt at writing a macro. Please let me know what I am doing incorrectly.

Public Sub Move_and_sort()
Dim IR As Long
Range("A3:M3").Copy.Range ("A" & IR & "B" & IR)
Range("A3: M3").Cell ClearContents
Range("A3:M" & IR).Sort Key1:=.Range("B3"), order1:=xlAscending, Header:=xlYes
Range("B3").Select
End With
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,125
Office Version
365
Platform
Windows
Welcome to the Board!

A few issues. You are missing the : from this line:
Code:
[COLOR=#333333]Range("A3:M3").Copy.Range ("A" & IR & "B" & IR)[/COLOR]
It should be:
Code:
[COLOR=#333333]Range("A3:M3").Copy.Range ("A" & IR & ":B" & IR)[/COLOR]
But more importantly, you haven't sent your IR variable equal to anything!
So, its values will be 0, and row 0 is not valid and will cause errors.
You need to set IR equal to something before using it.
 

Forum statistics

Threads
1,077,621
Messages
5,335,285
Members
399,011
Latest member
rodmicpc

Some videos you may like

This Week's Hot Topics

Top