SOLVED

ABOUT ADVANCE TABLE FUNCTIUON

Copper Contributor

I want to create table which do not have fix number of rows. If I input 10 in specific cell it will create 10 rows in table,etc.

Basically I want to create table which has number of rows I input in 1 specific cell.

Can anyone help me to write formula.

 

**Edited by moderator to remove caps lock **

6 Replies
best response confirmed by PRASHANT1497 (Copper Contributor)
Solution

@PRASHANT1497 -

 

This seems to work:

vba-dynamic-table-row.gif

 

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Dim tbl As ListObject
    Dim rowNum As Range
    Set tbl = ActiveSheet.ListObjects("tblDynamic")
    Set rowNum = Range("B3")
            
    Application.ScreenUpdating = False
    
    If Not Intersect(Target, Range("B3")) Is Nothing Then
        With tbl
            For i = .ListRows.Count To 1 Step -1
                .ListRows(i).Delete
            Next i
        End With
        Set rng = Range("tblDynamic[#All]").Resize(tbl.Range.Rows.Count + (rowNum - 1), tbl.Range.Columns.Count)
        tbl.Resize rng
    End If
    
    Application.ScreenUpdating = True
End Sub
Thank you but I can't understand I am beginner can you please show formula in given video or share by clicking image or share video including process of writing formula in excel
This method show some error and I can't decide it can you help me and explain what is the error
Hard for me to tell what the error is. I just recreated the file again and had no issues. Possibly because you have saved your file as .xlsx instead of .xlsm?

@PRASHANT1497 

 

Your code syntax is incorrect.

 

You have put

 Set tbl - ActiveSheet.ListObjects("tblDynamic")

instead of

 Set tbl = ActiveSheet.ListObjects("tblDynamic")

 

note one has a - and the other has an =

Thank you.
1 best response

Accepted Solutions
best response confirmed by PRASHANT1497 (Copper Contributor)
Solution

@PRASHANT1497 -

 

This seems to work:

vba-dynamic-table-row.gif

 

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Dim tbl As ListObject
    Dim rowNum As Range
    Set tbl = ActiveSheet.ListObjects("tblDynamic")
    Set rowNum = Range("B3")
            
    Application.ScreenUpdating = False
    
    If Not Intersect(Target, Range("B3")) Is Nothing Then
        With tbl
            For i = .ListRows.Count To 1 Step -1
                .ListRows(i).Delete
            Next i
        End With
        Set rng = Range("tblDynamic[#All]").Resize(tbl.Range.Rows.Count + (rowNum - 1), tbl.Range.Columns.Count)
        tbl.Resize rng
    End If
    
    Application.ScreenUpdating = True
End Sub

View solution in original post