Human_doing
Board Regular
- Joined
- Feb 16, 2011
- Messages
- 137
Hi all,
the below snippet of code is part of a project I'm working on, the final part I need is to be able to sort the cells A3:D + final row of data on each worksheet by the generated number in row D ascending, can anyone please help with the final line(s) of code, I think it may need to start with .Range("A3:D" & LR).Sort but not sure what comes after that?
Many thanks
the below snippet of code is part of a project I'm working on, the final part I need is to be able to sort the cells A3:D + final row of data on each worksheet by the generated number in row D ascending, can anyone please help with the final line(s) of code, I think it may need to start with .Range("A3:D" & LR).Sort but not sure what comes after that?
Many thanks
Code:
Dim Sh As Worksheet
Dim LR As Long
For Each Sh In ActiveWorkbook.Worksheets
With Sh
'Unmerge all cells
.Cells.MergeCells = False
'Delete unnecessary columns and rows
.Columns("A").Delete
.Rows("1:3").Delete
Sh.Name = Sh.Range("A2").Value
LR = .Range("C" & .Rows.Count).End(xlUp).Row
.Range("D4:D" & LR).Formula = "=RAND()*(1000-1)+1"
.Range("D4:D" & LR).Copy
.Range("D4:D" & LR).PasteSpecial xlPasteValuesAndNumberFormats
.Range("A3:D" & LR).Sort
End With
Next Sh