VBA code to cut/paste entire row if value exists in cell

Jastheace87

New Member
Joined
Jun 22, 2018
Messages
3
Hi All,

I am a VBA newbie and would like some help with getting the code right

background:
row number of these values are never constant, ie one day row D6 might contain the keyword minor the next D65 might contain the word minor. (Refer to screenshot)

goal:

I want to script to search column D for the keyword "Minor" select that entire row, cut it and paste it below the last cell in column A that contains data, the delete all the blank cells that were cut

current data / formatting:

1ABCDE
2TRUETRUE1Moderateyes
3TRUETRUE2Moderateno
4TRUETRUE3Majoryes
5FALSEFALSE4Majoryes
6TRUETRUE5Moderateno
7FALSEFALSE6Moderateyes
8FALSEFALSE7Moderateyes
9FALSEFALSE8Minorno
10TRUETRUE9Majoryes
11FALSEFALSE10Minoryes
12FALSEFALSE11Moderateno

<tbody>
</tbody>

desired data / formatting

1ABCDEF
2TRUETRUE3Majoryes3/01/2020
5FALSEFALSE8Majorno8/01/2020
6FALSEFALSE10Majoryes10/01/2020
7TRUETRUE1Moderateyes1/01/2020
8TRUETRUE2Moderateno2/01/2020
9TRUETRUE5Moderateno5/01/2020
10FALSEFALSE6Moderateyes6/01/2020
11FALSEFALSE7Moderateyes7/01/2020
12FALSEFALSE11Moderateno11/01/2020
13FALSEFALSEMinorno3/01/2020
14FALSEFALSEMinoryes4/01/2020
15FALSEFALSEMinoryes9/01/2020
16TRUETRUEMinorno8/01/2020


<tbody>
</tbody>

I have the code to search for the value and cut it but cannot figure out how to paste it below the last row of data on the activesheet


Sub Find_Vaule_Cut_Paste_lastrow()
'
' Find_Vaule_Cut_Paste_lastrow Macro
'


Dim sht As Worksheet
Dim LastRow As Long

Dim c As Range
Dim cell As Range
Dim SrchRng As Range
Dim SrchStr As String
Set sht = ActiveSheet


LastRow = Range("A" & Rows.Count).End(xlUp).Row




Set SrchRng = ActiveSheet.Range("E:E")
SrchStr = ("Minor")
For Each cell In SrchRng
If cell.Value = SrchStr Then cell.EntireRow.Cut Destination:=Range("A:" & LastRow)
Next cell
' LastRow.Select.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
How about
Code:
Sub MoveMinor()
   Dim rng As Range
   With Range("E:E")
      .Replace "Minor", "=XXXMinor", xlWhole, , False, , False, False
      Set rng = .SpecialCells(xlFormulas, xlErrors)
      .Replace "=XXXMinor", "Minor", xlWhole, , False, , False, False
      rng.EntireRow.Copy Range("A" & Rows.count).End(xlUp).Offset(1)
      rng.EntireRow.Delete
   End With
End Sub
 
Upvote 0
Hi Fluff
So sorry for the delay in replying to your post, I have only just had a chance to check MRExcel. Thanks so much for your code it works like a charm
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,221,444
Messages
6,159,912
Members
451,601
Latest member
terrynelson55

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top