ipbr21054
Well-known Member
- Joined
- Nov 16, 2010
- Messages
- 5,720
- Office Version
- 2007
- Platform
- Windows
Hi,
Code in use is shown below.
The code cuts the values from its original location on the worksheet then pastes them in the columns P-Z
Currently the values in columns P-Z are a table where i manually click the down arrow to sort A-Z
Row 3 are headers.
Row 4 is hidden.
Row 5 is where the value start.
I added some code shown in Red below so once values are pasted to then sort A-Z without me doing it manually.
The code now fails when trying to sort.
I see the following RTE 1004
Sort method of range class failed
Code in use is shown below.
The code cuts the values from its original location on the worksheet then pastes them in the columns P-Z
Currently the values in columns P-Z are a table where i manually click the down arrow to sort A-Z
Row 3 are headers.
Row 4 is hidden.
Row 5 is where the value start.
I added some code shown in Red below so once values are pasted to then sort A-Z without me doing it manually.
The code now fails when trying to sort.
I see the following RTE 1004
Sort method of range class failed
Rich (BB code):
Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim i As Long, j As Long
Dim lr As Long, lr2 As Long
Dim sh As Worksheet
Dim x As Long
Set sh = Sheets("GRASS")
With ListBox1
lr2 = sh.Range("Q" & Rows.Count).End(xlUp).Row + 1
If lr2 < 5 Then lr2 = 5
j = .ListIndex + 5
End With
With sh.Range("P" & lr2).Resize(1, 11)
.Value = sh.Range("A" & j).Resize(1, 11).Value
.Font.Size = 16
.Font.Bold = True
.Font.Name = "Calibri"
Application.ScreenUpdating = False
With Sheets("GRASS")
If .AutoFilterMode Then .AutoFilterMode = False
x = .Cells(.Rows.Count, 1).End(xlUp).Row
.Range("P4:Z" & x).Sort Key1:=Range("P5"), Order1:=xlAscending, Header:=xlGuess
End With
End With
With ListBox1
sh.Range("A" & j & ":K" & j).Delete Shift:=xlUp
lr = sh.Range("B" & Rows.Count).End(xlUp).Row
If lr > 4 Then .RowSource = sh.Name & "!A5:B" & lr
For i = 0 To .ListCount - 1
If .Selected(i) Then .Selected(i) = False
Next
End With
Unload SOCD
Range("A5").Select
End Sub