hejredersejre
New Member
- Joined
- Aug 5, 2013
- Messages
- 7
Dear Excel experts
I have made a macro that sorts my data in one sheet based on a value in a second sheet and then deletes the rows that doesn't contain the given value.
I have tried to enable the macro to consider more than one value when sorting but to no success
The macro takes quite a while to run. Is there any way the following code could be improved and hereby shortening the time it takes to run??
thank you in advance.
I have made a macro that sorts my data in one sheet based on a value in a second sheet and then deletes the rows that doesn't contain the given value.
I have tried to enable the macro to consider more than one value when sorting but to no success
The macro takes quite a while to run. Is there any way the following code could be improved and hereby shortening the time it takes to run??
thank you in advance.
Code:
Sub Button_13()
Sheets("Styring").Select
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim X As Long
Dim Y As Long
Dim Z As Long
Dim V As Long
X = Range("I43").Value
Y = Range("I45").Value
Z = Range("I47").Value
V = Range("I49").Value
Sheets("Data - Level 1").Select
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.DisplayPageBreaks = False
Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
For Lrow = Lastrow To Firstrow Step -1
With .Cells(Lrow, "A")
If Not IsError(.Value) Then
If .Value <> (X) Then .EntireRow.Delete
If .Value <> (Y) Then .EntireRow.Delete
If .Value <> (Z) Then .EntireRow.Delete
If .Value <> (V) Then .EntireRow.Delete
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
Last edited by a moderator: