Move and delete the active row in VBA

Tiny_t

New Member
Joined
Jan 31, 2014
Messages
14
Good Day,

I am working on a automated handover code to send an mail and all is working perfectly.

I would like to move the active cell to the next sheet after the last row there and then delete the blank row as well.

I have tried different examples from the web but with no luck

Code:
Sub Handover()
    
    Dim OutApp As Object
    Dim OutMail As Object
  Dim r As Integer
   
  
    For r = 2 To 200 'data in rows 2-4
    If Not IsEmpty(Sheets("WIP").Cells(r, 19)) Then
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    Dim Msg As String
    Dim signature As String


    
    
    Msg = ""
  
 
 
 SigString = "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Signatures\Auto.htm"


    If Dir(SigString) <> "" Then
        signature = GetBoiler(SigString)
    Else
        signature = ""
    End If


    On Error Resume Next
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = """
        .HTMLbody = Msg & vbNewLine & signature
        
        
        .display '.Send
        
    End With
    
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing
   
   
 
               
    Else
        End If
        Next r


End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Good Day,

I am working on a automated handover code to send an mail and all is working perfectly.

I would like to move the active cell to the next sheet after the last row there and then delete the blank row as well.

I have tried different examples from the web but with no luck

Code:
Sub Handover()
    
    Dim OutApp As Object
    Dim OutMail As Object
  Dim r As Integer
   
  
    For r = 2 To 200 'data in rows 2-4
    If Not IsEmpty(Sheets("WIP").Cells(r, 19)) Then
    
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
    Dim Msg As String
    Dim signature As String


    
    
    Msg = ""
  
 
 
 SigString = "C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Signatures\Auto.htm"


    If Dir(SigString) <> "" Then
        signature = GetBoiler(SigString)
    Else
        signature = ""
    End If


    On Error Resume Next
    With OutMail
        .To = ""
        .CC = ""
        .BCC = ""
        .Subject = """
        .HTMLbody = Msg & vbNewLine & signature
        
        
        .display '.Send
        
       
        

    End With
    
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing
   
   
 
               
    Else
        End If
        Next r


End Sub

had a blonde moment added code right after .Display

Sheets("WIP").Cells(r, 1).EntireRow.Cut Destination:= _
Sheets("Hand overs").Range("A" & Rows.Count).End(xlUp).Offset(1)
Sheets("WIP").Cells(r, 1).EntireRow.Delete

this is now working perfectly
 
Upvote 0
Works fine But only does one at a time and does not continue through the original list

so if i have 2 "handovers" i need to run the code twice
 
Upvote 0
Finally solved it

Code:
...
  .display '.Send
        
    End With
    
    Sheets("WIP").Cells(R, 1).EntireRow.Cut Destination:= _
    Sheets("Hand overs").Range("A" & Rows.Count).End(xlUp).Offset(1)
        
    
    On Error GoTo 0
    
    Set OutMail = Nothing
    Set OutApp = Nothing
   
  
        
         
    Else
        End If
        Next R
        
   Dim LastRow As Long
   Dim Counter As Long
   
   Application.ScreenUpdating = False
   LastRow = ActiveSheet.UsedRange.Rows.Count + ActiveSheet.UsedRange.Rows(1).Row - 1
   For R = LastRow To 1 Step -1
   If Application.WorksheetFunction.CountA(Rows(R)) = 0 Then
   Rows(R).Delete
   Counter = Counter + 1
   End If
   Next R
   Application.ScreenUpdating = True



End Sub
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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