Code only runs if on command button

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Morning,
Please can you advise on the issue i have.

If i put this code on a command button & it works fine.

Rich (BB code):
Private Sub DeleteCustomer_Click()
Dim tblName As String
Dim tbl As ListObject
Dim R As Long
Dim lr As Long
Dim i As Long
Dim ActiveTableRow As Long

If ActiveCell.Column = 19 And ActiveCell.Row > 3 And ActiveCell.Value = "X" Then
ActiveTableRow = Selection.Row - Selection.ListObject.Range.Row
Selection.ListObject.ListRows(ActiveTableRow).Delete
End If
End Sub

BUT
I have inserted it within an existing code that i use as shown below but the table row isnt deleted when X is in column S
Everything else in the code below works.

Rich (BB code):
Private Sub SUMMARYTRANSFER()
    Dim rFndCell As Range
    Dim stFnd As String
    Dim fRow As Long
    Dim sh As Worksheet
    Dim ws As Worksheet
    Dim tbl As ListObject
    Dim R As Long
    Dim lr As Long
    Dim i As Long
    Dim ActiveTableRow As Long

    Set ws = Sheets("G INCOME")
    Set sh = Sheets("G SUMMARY")
    stFnd = ws.Range("A3").Value
    
    With sh

    Set rFndCell = .Range("C5:C17").Find(stFnd, LookIn:=xlValues, LookAt:=xlWhole)
    If Not rFndCell Is Nothing Then
       
        fRow = rFndCell.Row
        sh.Cells(fRow, 4).Resize(, 1).Value = ws.Range("D31").Value
        sh.Cells(fRow, 5).Resize(, 1).Value = ws.Range("E31").Value
    Else
          MsgBox Range("A3") & vbNewLine & "WAS NOT FOUND IN THE RANGE", vbCritical + vbOKOnly, "NO MONTH IN SUMMARY SHEET RANGE"
          Worksheets("G SUMMARY").Activate
          Worksheets("G SUMMARY").Range("D3").Select
          Exit Sub
    End If
        MsgBox "TRANSFER TO SUMMARY SHEET ALSO COMPLETED", vbInformation + vbOKOnly, "SUMMARY TO TRANSFER SHEET COMPLETED MESSAGE"
        Sheets("G INCOME").Range("A5:B30").ClearContents
        Range("A3").MergeArea.ClearContents
        Range("C3").ClearContents
        Range("E3").ClearContents
        Range("A5").Select
    End With
    
    If ActiveCell.Column = 19 And ActiveCell.Row > 3 And ActiveCell.Value = "X" Then
        ActiveTableRow = Selection.Row - Selection.ListObject.Range.Row
        Selection.ListObject.ListRows(ActiveTableRow).Delete
    End If
    
    INCOMEMONTHYEAR.Show
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I believe its because i didnt select the cell which has the X in it to be deleted thus not making it the active cell.

How would i edit the code so i do not have to click the cell BUT the code just look fo an X value in column S & then delete the row in question
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
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