Eric Penfold
Active Member
- Joined
- Nov 19, 2021
- Messages
- 431
- Office Version
- 365
- Platform
- Windows
- Mobile
I need code to stop running when a Table called Table2 is already there. Some reason I can`t get the Function to work with main code?
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Rng
Dim Result As Integer
Call DeleteTbl
If Selection.Count > 1 Then Exit Sub
Set Rng = Range("J:J")
If Not Intersect(Target, Rng) Is Nothing Then
Result = MsgBox("Need to Send Depot Email Yes/No", vbInformation + vbYesNo, "Send Email Yes/No")
Select Case Result
Case vbYes
Call Email_Depot
Case vbNo
Exit Sub
End Select
End If
Range("A" & Cells.Rows.Count).End(xlUp).Select
Call CreateTbl
If TableExists = True Then
Exit Sub
End Sub
Function TableExists(tableName As String, sheetName As String) As Boolean
Dim targetSheet As Worksheet
Set targetSheet = Worksheets("Data")
Dim tbl As ListObject
With targetSheet
For Each tbl In .ListObjects
If tbl.Name = "Data2" Then TableExists = True
Next tbl
End With
End Function