Move Completed cells auto using VBA when they have been changed to completed

Clo112358

New Member
Joined
Jul 23, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I am trying to move cells on an excel document from FDJ- TIP to Completed TIP.

I used this in module:
VBA Code:
Sub MoveCompletedRows()
    Dim wsSource As Worksheet
    Dim wsDestination As Worksheet
    Dim lastRow As Long
    Dim i As Long

    ' Set your source and destination sheets
    Set wsSource = ThisWorkbook.Sheets("SourceSheet")
    Set wsDestination = ThisWorkbook.Sheets("DestinationSheet")

    ' Find the last row with data in the source sheet
    lastRow = wsSource.Cells(wsSource.Rows.Count, "A").End(xlUp).Row

    ' Loop through each row from the bottom up
    For i = lastRow To 1 Step -1
        If wsSource.Cells(i, 6).Value = "Completed" Then ' Check if column F (6) is "Completed"
            wsSource.Rows(i).Copy Destination:=wsDestination.Rows(wsDestination.Cells(wsDestination.Rows.Count, "A").End(xlUp).Row + 1)
            wsSource.Rows(i).Delete
        End If
    Next i
End Sub



And this in the tab sheet:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Me.Range("F:F")) Is Nothing Then
        Call MoveCompletedRows
    End If
End Sub



It worked on a test sheet and then when applied to the live document it stopped working and wont move the row
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
looks ok to me. make sure your data occupies column A on which you base your last row count. also, make sure that you are making a change in column F which will trigger your macro. i don't think pasting new data in is enough to trigger a macro. changing the value of an existing cell and pressing enter should do it though. if it worked on your test sheet, check that you are doing everything the same. Create a separate Sub like this: Sub ee(): Application.EnableEvents = True: End Sub, then press F5 and try yours again. just served dinner. will test what you have provided above after i have eaten and see what happens. sadly, i find myself in similar situations now and again. best of luck.
 
Upvote 0
It worked on a test sheet and then when applied to the live document it stopped working and wont move the row
Hi welcome to forum

How are you changing value(s) in Column F of your source sheet - direct input or by formula?

Dave
 
Upvote 0
Code works fine. You have to actually enter "Completed" (case sensitive) into column F.
 
Upvote 0
As you stated your code did work once then trying running this code from a STANDARD module & then try your code again

VBA Code:
Sub Reset()
 Application.EnableEvents = True
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,112
Members
453,021
Latest member
Justyna P

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