largeselection
Active Member
- Joined
- Aug 4, 2008
- Messages
- 358
Hi,
I have some code that will go through a table and delete the fields that I have deselected on a different tab. The part where I am having difficulty is the ListObject.ListColumns(#).Delete part. The problem is that the # changes, but I haven't put it in my code correctly to dynamically change (I copied what was recorded while I did it as this is the first time I'm deleting fields via VBA from a table).
How can I get the # to update to the correct column #.
As an example, I might have the field "NAME" in column C, my code says
And I have other code before this which identifies tfield = "NAME"
The issue that I have realized is that I have successfully selected the field I want to delete, but then specify that I want to delete the first column (ListColumns(1)) even though this is the 3rd column in.
So how can I say something along the lines of:
Delete whatever the listcolumn is of the current selection?
Thanks in advance!
Please let me know if you have any questions.
I have some code that will go through a table and delete the fields that I have deselected on a different tab. The part where I am having difficulty is the ListObject.ListColumns(#).Delete part. The problem is that the # changes, but I haven't put it in my code correctly to dynamically change (I copied what was recorded while I did it as this is the first time I'm deleting fields via VBA from a table).
How can I get the # to update to the correct column #.
As an example, I might have the field "NAME" in column C, my code says
Code:
Range("Table[[#Headers],[" & tfield & "]]").Select
Selection.ListObject.ListColumns(1).Delete
And I have other code before this which identifies tfield = "NAME"
The issue that I have realized is that I have successfully selected the field I want to delete, but then specify that I want to delete the first column (ListColumns(1)) even though this is the 3rd column in.
So how can I say something along the lines of:
Delete whatever the listcolumn is of the current selection?
Thanks in advance!
Please let me know if you have any questions.