+ Reply to Thread
Results 1 to 23 of 23

how to tell if a table exists in a worksheet

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    how to tell if a table exists in a worksheet

    how can i tell if a table (there will be only 1 per sheet) exists in a worksheet.

    i have tried the following:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    how can i get this to work?

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: how to tell if a table exists in a worksheet

    What do you want to do if it does?
    Maybe:

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    so i used what you said and did the following:

    Please Login or Register  to view this content.
    but the message box never appears, the target.clear doesn't do it and finally it doesn't make the table. what am i doing wrong?

    to answer your question, if there is a table, do nothing. if there is no table, then create one and give a total row.

  4. #4
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    i also tried the following:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to tell if a table exists in a worksheet

    Hi,

    It's
    Please Login or Register  to view this content.
    and not what you have which is
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: how to tell if a table exists in a worksheet

    Where is your code? Is it Sheet Code? Where does Target.ClearContents come from? Can you post the entire code?

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    xlnitwit. yup i see that now. :-(

    john, here is the entire sheet code:

    Please Login or Register  to view this content.
    the case statement "Make Table" is the code that i am looking for. does this help?

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to tell if a table exists in a worksheet

    Perhaps
    Please Login or Register  to view this content.
    If the MakeTableWithTotalRow routine is in the same workbook, you should call it directly instead of using Run. Also, there is no point to using Range(Target.Address) since it just returns the same range as Target.

  9. #9
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    i tried that and nothing happened. i verified that there is no table on the sheet. i would like to upload a sample workbook but have to get rid of all the data. give me a minute to do that.

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to tell if a table exists in a worksheet

    At the very least you might post the code for MakeTableWithTotalRow?

  11. #11
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: how to tell if a table exists in a worksheet

    Maybe?

    Please Login or Register  to view this content.

  12. #12
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    john, i tried that and it appears to do nothing.

    xlnitwit, here is the code for maketablewithtotalrow but now i can see that it needs to be fixed. i originally created a table called prtable. this worked when it was just a macro and not fired from row k as an action. so i am sure this needs to be recoded.

    Please Login or Register  to view this content.
    im going to recode for just a messagebox to see if the action is working as expected.

  13. #13
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to tell if a table exists in a worksheet

    Perhaps this version
    Please Login or Register  to view this content.

  14. #14
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    so made some progress with your help.

    john, made clerical error (i so hate spaces), now routine is working as you wrote it.

    xlnitwit,

    thanks for that code. made a few changes and it looks like this:

    Please Login or Register  to view this content.
    wanted to account for dynamic data (not a fixed row) so lastrow does that. so that helps to make this action work as expected.

    thanks to both of you.

  15. #15
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: how to tell if a table exists in a worksheet

    You're welcome. Glad I could contribute, and thanks for the feedback and reps.

  16. #16
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    so im working on the update notes case. got the if statement working for either table or range. but i need help with the range part. tried to do offset, but couldn't make the syntax correct. what am i doing wrong?


    Please Login or Register  to view this content.
    so the target.address correctly identifies the changed cell(col K), but the field i want to update is in column G so that is why i tried the offset that i did.

    any help is appreciated.

  17. #17
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: how to tell if a table exists in a worksheet

    Target is a range object so you only need
    Please Login or Register  to view this content.

  18. #18
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    thanks xlnitwit, that worked.

    i also found this to work as well

    Please Login or Register  to view this content.

  19. #19
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    so i put the following code in my "Closed POs" sheet.

    [CODE]
    Private Sub Worksheet_Change(ByVal Target As Range)

    Dim KeyCells As Range

    Dim FullExcelPath As String

    FullExcelPath = ThisWorkbook.FullName
    'MsgBox FullExcelPath

    Application.DisplayAlerts = False

    ' The variable KeyCells contains the cells that will
    ' cause an alert when they are changed.
    Set KeyCells = Range("d:d")

    If Not Application.Intersect(KeyCells, Range(Target.Address)) _
    Is Nothing Then
    Select Case Target.Value
    Case Is < Now - 30
    MsgBox "Move to Closed PO archive file"
    Case Is >= Now - 30
    MsgBox "Keep for now"
    Case Else
    MsgBox "Case Else"
    End Select
    End If
    End Sub
    /CODE]

    so the stub works as expected, when i change dates it goes through the case statement properly. but what i really want is for this to be a OPEN worksheet event as well. it should check the Aging date in column D and see if its a month old or older.

    i figure this should be a worksheet event but im not sure of how to transfer the code in the stub to the ThisWorkbook code sheet.

    thoughts?
    Last edited by dmcgov; 08-23-2017 at 08:44 AM.

  20. #20
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: how to tell if a table exists in a worksheet

    There is a Workbook Sheet Change Event which is appied to every sheet if that's what you're looking for?

    Please Login or Register  to view this content.
    Or if you're looking too activate the sheet on Workbooks Open Event then:

    Please Login or Register  to view this content.

  21. #21
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    John,

    Neither work as I expect. The first didnt work as expected, and the second error'ed out with a "run time error - 1004, Activate method of worksheet class failed" code. Let me explain what i am looking for.

    i have a worksheet change event that fires on the "Closed POs" sheet. the keycell is column D. and it works as expected, when i change a date, i get a messagebox. which is what i want for this stub. So lets say that i put a date in D2 that is 7/25/17 which is one day less than the 30 (in my code) so the message box says to "Keep for Now". Then I save the file. When I return to the file the next day and open it, i want the workbook open event to check all the cells in column d to see if they need to get moved to the closed archived file or just leave it alone (and give me a messagebox).

    How can that be done?

  22. #22
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    so i realize that the code will have to be completely overhauled. cant use intersect cause the date might already be old without changing the value on the sheet. the code would have to look at just the "Closed POs" sheet, examine each cell in the target.range and then do a messagebox. how can i do that?

  23. #23
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to tell if a table exists in a worksheet

    so this last question doesn't go with the OP, so im going to close this and open up a new case.

    thanks to everyone for their help.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Can't name a table as the name exists, but it does not!?
    By brucemc777 in forum Excel General
    Replies: 0
    Last Post: 11-04-2015, 08:05 PM
  2. [SOLVED] If Worksheet Exists
    By ChrisMattock in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2015, 11:16 AM
  3. Check if Worksheet exists and Insert Worksheet
    By ddanmcgrew in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2012, 03:19 PM
  4. Replies: 6
    Last Post: 08-04-2011, 12:18 PM
  5. worksheet exists or not
    By skvabbili in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-04-2006, 05:50 PM
  6. Worksheet exists
    By Kaval in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2006, 04:55 AM
  7. check if worksheet exists
    By joeeng in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1