I am trying to determine by VBA in Excel 2013 if the ActiveCell is not just in any table, but in a specific table.
Below is the code as is, but only detects ActiveCell being in any table. The commented out line is what I'm looking for, but obviously it doesn't work.
... Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange) 'Set rng = Intersect(.EntireRow, ActiveCell.ListObjects("myTable").DataBodyRange) On Error GoTo 0 If rng Is Nothing Then MsgBox "Please select the cell of a row within the consensus input table.", vbCritical, "Delete Evaluator" Else ...
Any suggestions on the right syntax for this?
Thanks!
Select one or more rows and columns Or click on any cell in the column and then press Ctrl + Space. Select the row number to select the entire row. Or click on any cell in the row and then press Shift + Space.
You can use the "offset" property to change which cell you want to select based on where your active cell is. This will offset the active cell down 0 rows and to the right 2 columns. If you ever want to go the other way just put (-)negative signs in front of the numbers. Hope this helps!
Excel allows you to easily see the location of the currently selected cell by examining the contents of the Name Box, to the left of the Formula Bar.
To test if ActiveCell is in the body of Table1:
Sub qwerty()
If Intersect(ActiveCell, ActiveSheet.ListObjects("Table1").DataBodyRange) Is Nothing Then
MsgBox "activecell not in Table1"
Else
MsgBox "activecell in Table1"
End If
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With