PritishS
Board Regular
- Joined
- Dec 29, 2015
- Messages
- 119
- Office Version
- 2007
- Platform
- Windows
Dear Sirs/Madams,
I have a code which search for a specific text 'PEN COLOR' in column 2, select that cell and 1 cell to right, then cut the selection and paste 1 cell right to the same row. My code works fine for small amount of data ( or rows (around 1000 rows), but when it goes for large number of rows then it's taking several minutes. Can anyone please suggest any betterment in this below code?
Thanks in advance.
Regards,
PritishS
I have a code which search for a specific text 'PEN COLOR' in column 2, select that cell and 1 cell to right, then cut the selection and paste 1 cell right to the same row. My code works fine for small amount of data ( or rows (around 1000 rows), but when it goes for large number of rows then it's taking several minutes. Can anyone please suggest any betterment in this below code?
VBA Code:
Sub Move_Pen_Name()
Dim ws As Worksheet
Dim aCell As Range
Dim i As Long
Application.ScreenUpdating = False
Set ws = ActiveSheet
For i = 1 To Rows.Count
With ws
Set aCell = .Columns(2).Find(What:="PEN COLOR", LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True, SearchFormat:=False)
If Not aCell Is Nothing Then
aCell.Select
ActiveCell.Offset(, 1).Resize(1, 1).Cut
Range(Cells(Selection.Row, 2).Address).Select
ActiveSheet.Paste
Else
Exit Sub
End If
End With
Next i
Application.ScreenUpdating = True
End Sub
Thanks in advance.
Regards,
PritishS