Chris Macro
Well-known Member
- Joined
- Nov 2, 2011
- Messages
- 1,345
- Office Version
- 365
- Platform
- Windows
I want to make a macro that based on the cells selected, the macro will delete the table row (corresponding with the selected cell row). I would also like to show an error message if the selection is outside the table (we can call it table 1 for now). Here is what I have so far:
Error on:
Rest of Code:
<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> DeleteRow()<br><br><SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br><SPAN style="color:#00007F">With</SPAN> Selection<br> x = .ListObject.ListRow.Index<br> .ListObject.ListRows(x).Delete<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
Error on:
Code:
x = .ListObject.ListRow.Index
Rest of Code:
<font face=Calibri><SPAN style="color:#00007F">Sub</SPAN> DeleteRow()<br><br><SPAN style="color:#00007F">Dim</SPAN> x <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br><SPAN style="color:#00007F">With</SPAN> Selection<br> x = .ListObject.ListRow.Index<br> .ListObject.ListRows(x).Delete<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>