Results 1 to 6 of 6

Excel 2007 Table Problem (Add/Delete Row)

Threaded View

Craxuan Excel 2007 Table Problem... 04-03-2011, 04:07 PM
Roger Govier Re: Excel 2007 Table Problem... 04-03-2011, 05:45 PM
nimrod Re: Excel 2007 Table Problem... 04-03-2011, 05:46 PM
nimrod Re: Excel 2007 Table Problem... 04-03-2011, 05:59 PM
nimrod Re: Excel 2007 Table Problem... 04-03-2011, 06:04 PM
Craxuan Re: Excel 2007 Table Problem... 04-04-2011, 12:57 AM
  1. #1
    Registered User
    Join Date
    04-03-2011
    Location
    Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    10

    Excel 2007 Table Problem (Add/Delete Row)

    I'm a complete newbie in Excel VBA and was forced to learn it within days to complete a university project, and now I'm stuck. The idea was to select between 0 to 8 from a drop-down list to generate a table with number of rows similar to the picked choice and 2 columns. Selecting 0 would clear away the table, select 1 would generate a table with 1 row, 2 for 2 rows...

    The problem is that no matter what I try, it always says 'overlapping table' with the exception of 0 (There are other kind of errors as well specific to the methods I try). I do not know the proper way to write the code for adding or deleting rows or columns, and have tried and tested very hard but I still can't make it work. Also, is it possible that I could predefine the column title of the generated table? Please help! I've also attached a picture for better understanding.

    Private Sub Workbook_Open()
    
    End Sub
    
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    Select Case Range("B21")
    
    
    Case "0"
    Range("$A$24:$B$32").Clear
    
    Case "1"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$25"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    ActiveSheet.ListObjects("CLOTable").Range("A24").Select
    
    Case "2"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$26"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    
    Case "3"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$27"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    
    Case "4"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$28"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    
    Case "5"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$29"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    
    Case "6"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$30"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    
    Case "7"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$31"), , xlYes).Name = "CLOTable"
    ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    
    Case "8"
    
    ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$24:$B$32"), , xlYes).Name = "CLOTable"
     ActiveSheet.ListObjects("CLOTable").TableStyle = "TableStyleLight2"
    End Select
    
    End Sub
    Attached Images Attached Images
    Last edited by pike; 04-03-2011 at 06:23 PM. Reason: add code tags for newbie pm rules

Thread Information

Users Browsing this Thread

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

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