VBA If True, then cut and paste to a new worksheet

freshwattrout

New Member
Joined
Jul 17, 2021
Messages
3
Office Version
  1. 2016
Platform
  1. Windows
I need help to make a VBA macro that looks up column B in the source sheet, determines if the value is "Y", and cuts and pastes rows C:F to the destination worksheet. I currently have the following code:

VBA Code:
Option Explicit

Sub Completed()
 
    
    Windows("Kitting.xlsx").Activate
    Dim LastRow As Long, i As Long
    LastRow = Cells(Rows.Count, "B").End(xlUp).Row
    
    For i = 2 To LastRow
    If Range("B" & i).Value = "Y" Then
    Dim pn As String
    pn = Range("C" & i).Value
    Sheets("Completed").Select
    Sheets("Completed").Range("C" & i).Value = pn
    End If
   
    Windows("Production Schedule 2021.xlsm").Activate
    Next i
    
End Sub

Source sheet (KITTING PRIORITY)
1628010755974.png

Destination worksheet (Completed)
1628010832548.png
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Do you mean to "cut and paste" the Range(Ci:Fi) or "Copy and paste"?
 
Upvote 0
Why are you activating workbooks? Aren't the source and completed worksheets in the same workbook? And if so, aren't you calling the macro from the active workbook already?
 
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,497
Members
448,967
Latest member
visheshkotha

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