How to loop for each table in one sheet VBAExcel VBA to determine last non-value (IE may have a formula but no value) row in columnHow to avoid using Select in Excel VBAactivesheet in excel VBATable ListObject not limited to rows of table but counts the whole sheetConditional copy Excel File-2 data to excel file-1?Vba Code to Delete data based on a drop box choiceTake the date in one worksheet and find the same date in another worksheet column and return the cell reference for that date to use in a loopVBA Function Not Working with nested loopsexcel VBA code to ignore an email attachment if missing from folder

What's weird about Proto-Indo-European Stops?

Why were the rules for Proliferate changed?

Game artist computer workstation set-up – is this overkill?

What's the difference between "ricochet" and "bounce"?

Appropriate age to involve kids in life changing decisions

My large rocket is still flipping over

I want to write a blog post building upon someone else's paper, how can I properly cite/credit them?

Many one decreasing function?

Select list elements based on other list

How to increase speed on my hybrid bike with flat handlebars and 700X35C tyres?

If an attacker targets a creature with the Sanctuary spell cast on them, but fails the Wisdom save, can they choose not to attack anyone else?

What did Varys actually mean?

Texture vs. Material vs. Shader

Learning how to read schematics, questions about fractional voltage in schematic

Good introductory book to type theory?

Why did Gendry call himself Gendry Rivers?

Displaying an Estimated Execution Plan generates CXPACKET, PAGELATCH_SH, and LATCH_EX [ACCESS_METHODS_DATASET_PARENT] waits

While drilling into kitchen wall, hit a wire - any advice?

If quadruped mammals evolve to become bipedal will their breast or nipple change position?

Convert a huge txt-file into a dataset

What is the meaning of "matter" in physics?

My C Drive is full without reason

A problem with Hebrew and English underlined text

Extracting the parent, leaf, and extension from a valid path



How to loop for each table in one sheet VBA


Excel VBA to determine last non-value (IE may have a formula but no value) row in columnHow to avoid using Select in Excel VBAactivesheet in excel VBATable ListObject not limited to rows of table but counts the whole sheetConditional copy Excel File-2 data to excel file-1?Vba Code to Delete data based on a drop box choiceTake the date in one worksheet and find the same date in another worksheet column and return the cell reference for that date to use in a loopVBA Function Not Working with nested loopsexcel VBA code to ignore an email attachment if missing from folder






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















im trying to generate lists of table and column to txt file from excel file.
my code just generate for all clumn until end of row because i have no idea how to define variable to limit looping each table :



here the code and excel data image Excel data



Dim field As String
Dim table As String
Dim t As Integer
Dim f As Integer
Dim lastrow As Integer
Dim myFile As String
Dim xStr As String

myFile = "D:table.txt"

With Sheets("Sheet1")
Open myFile For Output As #1

table = """table_name"": """ & .Range("I2") & ""","
Print #1, table

lastrow = Range("A" & Rows.Count).End(xlUp).Row

For f = 2 To lastrow
field = """column_name"": [" & Chr(10) & """" & .Range("B" & f) & """" & Chr(10) & _
"],"
Print #1, field
Next f

Close #1


End With


I imagine the code like below(CMIIW the logic), but how to write this on vba:



for t = 1 to "count table on sheet (i dnt know how to define this value)"
table = "tablename"
Print #1, table

for f = "first row table t + 1" to lastrow table t
field= "fieldname"
Print #1, field
Next f
Next t


Base on answer of user11246173 i know how to loop as number of table count,
but i still cant get the range of each specific cell like my code above.
Please help to resolve my code.



Anyone can please help me on this?










share|improve this question






























    0















    im trying to generate lists of table and column to txt file from excel file.
    my code just generate for all clumn until end of row because i have no idea how to define variable to limit looping each table :



    here the code and excel data image Excel data



    Dim field As String
    Dim table As String
    Dim t As Integer
    Dim f As Integer
    Dim lastrow As Integer
    Dim myFile As String
    Dim xStr As String

    myFile = "D:table.txt"

    With Sheets("Sheet1")
    Open myFile For Output As #1

    table = """table_name"": """ & .Range("I2") & ""","
    Print #1, table

    lastrow = Range("A" & Rows.Count).End(xlUp).Row

    For f = 2 To lastrow
    field = """column_name"": [" & Chr(10) & """" & .Range("B" & f) & """" & Chr(10) & _
    "],"
    Print #1, field
    Next f

    Close #1


    End With


    I imagine the code like below(CMIIW the logic), but how to write this on vba:



    for t = 1 to "count table on sheet (i dnt know how to define this value)"
    table = "tablename"
    Print #1, table

    for f = "first row table t + 1" to lastrow table t
    field= "fieldname"
    Print #1, field
    Next f
    Next t


    Base on answer of user11246173 i know how to loop as number of table count,
    but i still cant get the range of each specific cell like my code above.
    Please help to resolve my code.



    Anyone can please help me on this?










    share|improve this question


























      0












      0








      0








      im trying to generate lists of table and column to txt file from excel file.
      my code just generate for all clumn until end of row because i have no idea how to define variable to limit looping each table :



      here the code and excel data image Excel data



      Dim field As String
      Dim table As String
      Dim t As Integer
      Dim f As Integer
      Dim lastrow As Integer
      Dim myFile As String
      Dim xStr As String

      myFile = "D:table.txt"

      With Sheets("Sheet1")
      Open myFile For Output As #1

      table = """table_name"": """ & .Range("I2") & ""","
      Print #1, table

      lastrow = Range("A" & Rows.Count).End(xlUp).Row

      For f = 2 To lastrow
      field = """column_name"": [" & Chr(10) & """" & .Range("B" & f) & """" & Chr(10) & _
      "],"
      Print #1, field
      Next f

      Close #1


      End With


      I imagine the code like below(CMIIW the logic), but how to write this on vba:



      for t = 1 to "count table on sheet (i dnt know how to define this value)"
      table = "tablename"
      Print #1, table

      for f = "first row table t + 1" to lastrow table t
      field= "fieldname"
      Print #1, field
      Next f
      Next t


      Base on answer of user11246173 i know how to loop as number of table count,
      but i still cant get the range of each specific cell like my code above.
      Please help to resolve my code.



      Anyone can please help me on this?










      share|improve this question
















      im trying to generate lists of table and column to txt file from excel file.
      my code just generate for all clumn until end of row because i have no idea how to define variable to limit looping each table :



      here the code and excel data image Excel data



      Dim field As String
      Dim table As String
      Dim t As Integer
      Dim f As Integer
      Dim lastrow As Integer
      Dim myFile As String
      Dim xStr As String

      myFile = "D:table.txt"

      With Sheets("Sheet1")
      Open myFile For Output As #1

      table = """table_name"": """ & .Range("I2") & ""","
      Print #1, table

      lastrow = Range("A" & Rows.Count).End(xlUp).Row

      For f = 2 To lastrow
      field = """column_name"": [" & Chr(10) & """" & .Range("B" & f) & """" & Chr(10) & _
      "],"
      Print #1, field
      Next f

      Close #1


      End With


      I imagine the code like below(CMIIW the logic), but how to write this on vba:



      for t = 1 to "count table on sheet (i dnt know how to define this value)"
      table = "tablename"
      Print #1, table

      for f = "first row table t + 1" to lastrow table t
      field= "fieldname"
      Print #1, field
      Next f
      Next t


      Base on answer of user11246173 i know how to loop as number of table count,
      but i still cant get the range of each specific cell like my code above.
      Please help to resolve my code.



      Anyone can please help me on this?







      excel vba






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 29 at 2:28







      Great Saiyaman

















      asked Mar 23 at 6:28









      Great SaiyamanGreat Saiyaman

      177




      177






















          1 Answer
          1






          active

          oldest

          votes


















          0














          In VBA, worksheet tables are called ListObjects. They are a collection that belongs to the parent worksheet and (among other properties) have a count and an index as do most other collection objects. Each ListObject has a number of ListColumns.



          Option Explicit

          Sub loopLO()

          Dim i As Long, c As Long

          With Worksheets("sheet1")
          For i = 1 To .ListObjects.Count
          Debug.Print .ListObjects(i).Name
          For c = 1 To .ListObjects(i).ListColumns.Count
          Debug.Print .ListObjects(i).ListColumns(c)
          Next c
          Next i
          End With

          End Sub





          share|improve this answer























          • i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

            – Great Saiyaman
            Mar 23 at 7:19











          • Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

            – user11246173
            Mar 23 at 7:25











          • i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

            – Great Saiyaman
            Mar 23 at 8:11












          • Try worksheets("sheet1").listobjects("table1").range.cells(1).address

            – user11246173
            Mar 23 at 8:16











          • i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

            – Great Saiyaman
            Mar 23 at 9:01











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311221%2fhow-to-loop-for-each-table-in-one-sheet-vba%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          In VBA, worksheet tables are called ListObjects. They are a collection that belongs to the parent worksheet and (among other properties) have a count and an index as do most other collection objects. Each ListObject has a number of ListColumns.



          Option Explicit

          Sub loopLO()

          Dim i As Long, c As Long

          With Worksheets("sheet1")
          For i = 1 To .ListObjects.Count
          Debug.Print .ListObjects(i).Name
          For c = 1 To .ListObjects(i).ListColumns.Count
          Debug.Print .ListObjects(i).ListColumns(c)
          Next c
          Next i
          End With

          End Sub





          share|improve this answer























          • i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

            – Great Saiyaman
            Mar 23 at 7:19











          • Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

            – user11246173
            Mar 23 at 7:25











          • i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

            – Great Saiyaman
            Mar 23 at 8:11












          • Try worksheets("sheet1").listobjects("table1").range.cells(1).address

            – user11246173
            Mar 23 at 8:16











          • i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

            – Great Saiyaman
            Mar 23 at 9:01















          0














          In VBA, worksheet tables are called ListObjects. They are a collection that belongs to the parent worksheet and (among other properties) have a count and an index as do most other collection objects. Each ListObject has a number of ListColumns.



          Option Explicit

          Sub loopLO()

          Dim i As Long, c As Long

          With Worksheets("sheet1")
          For i = 1 To .ListObjects.Count
          Debug.Print .ListObjects(i).Name
          For c = 1 To .ListObjects(i).ListColumns.Count
          Debug.Print .ListObjects(i).ListColumns(c)
          Next c
          Next i
          End With

          End Sub





          share|improve this answer























          • i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

            – Great Saiyaman
            Mar 23 at 7:19











          • Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

            – user11246173
            Mar 23 at 7:25











          • i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

            – Great Saiyaman
            Mar 23 at 8:11












          • Try worksheets("sheet1").listobjects("table1").range.cells(1).address

            – user11246173
            Mar 23 at 8:16











          • i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

            – Great Saiyaman
            Mar 23 at 9:01













          0












          0








          0







          In VBA, worksheet tables are called ListObjects. They are a collection that belongs to the parent worksheet and (among other properties) have a count and an index as do most other collection objects. Each ListObject has a number of ListColumns.



          Option Explicit

          Sub loopLO()

          Dim i As Long, c As Long

          With Worksheets("sheet1")
          For i = 1 To .ListObjects.Count
          Debug.Print .ListObjects(i).Name
          For c = 1 To .ListObjects(i).ListColumns.Count
          Debug.Print .ListObjects(i).ListColumns(c)
          Next c
          Next i
          End With

          End Sub





          share|improve this answer













          In VBA, worksheet tables are called ListObjects. They are a collection that belongs to the parent worksheet and (among other properties) have a count and an index as do most other collection objects. Each ListObject has a number of ListColumns.



          Option Explicit

          Sub loopLO()

          Dim i As Long, c As Long

          With Worksheets("sheet1")
          For i = 1 To .ListObjects.Count
          Debug.Print .ListObjects(i).Name
          For c = 1 To .ListObjects(i).ListColumns.Count
          Debug.Print .ListObjects(i).ListColumns(c)
          Next c
          Next i
          End With

          End Sub






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 23 at 6:42







          user11246173



















          • i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

            – Great Saiyaman
            Mar 23 at 7:19











          • Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

            – user11246173
            Mar 23 at 7:25











          • i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

            – Great Saiyaman
            Mar 23 at 8:11












          • Try worksheets("sheet1").listobjects("table1").range.cells(1).address

            – user11246173
            Mar 23 at 8:16











          • i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

            – Great Saiyaman
            Mar 23 at 9:01

















          • i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

            – Great Saiyaman
            Mar 23 at 7:19











          • Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

            – user11246173
            Mar 23 at 7:25











          • i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

            – Great Saiyaman
            Mar 23 at 8:11












          • Try worksheets("sheet1").listobjects("table1").range.cells(1).address

            – user11246173
            Mar 23 at 8:16











          • i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

            – Great Saiyaman
            Mar 23 at 9:01
















          i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

          – Great Saiyaman
          Mar 23 at 7:19





          i think its work, but i need set format as table for each table in my excel, any automatic way to format as table in each table?

          – Great Saiyaman
          Mar 23 at 7:19













          Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

          – user11246173
          Mar 23 at 7:25





          Creating a ListObject is not 'set format as table'. Record yourself applying Ctrl+T to some cells.

          – user11246173
          Mar 23 at 7:25













          i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

          – Great Saiyaman
          Mar 23 at 8:11






          i implement your code to my code, but i still dnt know how to get first row id from table (i), becasue i need get table name at cell I2 dan I10 like image i attach. i think i need code like table = """table_name"": """ & .Range("I" & .table(i).first row (idk how to code this) + 1) & ""","

          – Great Saiyaman
          Mar 23 at 8:11














          Try worksheets("sheet1").listobjects("table1").range.cells(1).address

          – user11246173
          Mar 23 at 8:16





          Try worksheets("sheet1").listobjects("table1").range.cells(1).address

          – user11246173
          Mar 23 at 8:16













          i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

          – Great Saiyaman
          Mar 23 at 9:01





          i still not got the poin. i want to conacate to other string so i need more specific row id, i tried Print #1, .ListObjects(i).ListColumns(2,2) 2,2 mean i tried to get row B2

          – Great Saiyaman
          Mar 23 at 9:01



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55311221%2fhow-to-loop-for-each-table-in-one-sheet-vba%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript