How to do single button action for multi sheet (tabs) excel using VB script?












-1















I am a beginner in VB script and I have a excel sheet with multi tab . I have created a one button inside one excel sheet . Another sheets having some table . I want to generate some code inside a file with those excel tables using a simple button .



For example :



This excel book have one tab called Generate . Inside Generate i have created one button .



enter image description here



I have another tab named country which contain a table for country list



enter image description here



I have another tab also named car which contain a table for car list



enter image description here



Now i want to create a file "output.txt" which should create with some code from both tabs (country and vehicle )when click Generate code button .



My output.txt format :



*from sheet1 Country*/

VAR const US =
{
0x0,/*binary 00000*/
0xB,/*binary 01011*/
0x3,/*binary 00011*/
0x3,/*binary 00011*/
0xB,/*binary 01011*/
1xB /*binary 11011*/
};

//need to crate hexa array for Uk,france,brazil and india

VAR DefaultCountry =
{
invalid,
UK,
Brazil,
Brazil,
UK,
India
};

/* from sheet2 car */

VAR const polo =
{

};

//need to crate hexa array for BMW,i20,Swift and wagnor

VAR DefaultCAR =
{
invalid,
BMW,
Swift,
Swift,
BMW,
Wagnor
}


excelsheet.txt format :



const exceldetails[Maxindex] = 
{
/* index 0 */
/* index 1 */
{
{ UK, India, brazil,eMaxNoOfcountry, eMaxNoOfcountry},
{BMW, Wagnor, Swift,eMaxNoOfcar,eMaxNoOfcar },
index1,
},
/*index 2*/
etc..
};




  1. If the column has "-" , it should take 0 value and if it is integer , it should take 1 value and print the hexa value and binary value both



    eg: for country index 0 : - - - - - => binary : 00000 => hexa : 0x0
    index 1 : - 1 - 3 2 => binary : 01011 => hexa : 0xB



    Array name : VAR const US,france etc.. VAR const polo,swift etc..




  2. If the column contain 1 , It is default value and print the default value column name for each index in array



    array name : VAR DefaultCountry,VAR DefaultCAR)




  3. Create another file "exceldetails.txt" and write the order of each country and car details in array . If "-" present take as eMaxNoOf.



    array name : exceldetails[Maxindex])




How to do this ? Any help ? Any Reference also be helpful . How to use one button for taking table values from multi tabs?










share|improve this question

























  • What exactly are you having problems with? Forgetting the button for now, can you do everything else?

    – Tim Williams
    Nov 15 '18 at 20:46











  • yes . i want to know how to traverse each tabs (sheets) tables

    – user2986042
    Nov 15 '18 at 21:15
















-1















I am a beginner in VB script and I have a excel sheet with multi tab . I have created a one button inside one excel sheet . Another sheets having some table . I want to generate some code inside a file with those excel tables using a simple button .



For example :



This excel book have one tab called Generate . Inside Generate i have created one button .



enter image description here



I have another tab named country which contain a table for country list



enter image description here



I have another tab also named car which contain a table for car list



enter image description here



Now i want to create a file "output.txt" which should create with some code from both tabs (country and vehicle )when click Generate code button .



My output.txt format :



*from sheet1 Country*/

VAR const US =
{
0x0,/*binary 00000*/
0xB,/*binary 01011*/
0x3,/*binary 00011*/
0x3,/*binary 00011*/
0xB,/*binary 01011*/
1xB /*binary 11011*/
};

//need to crate hexa array for Uk,france,brazil and india

VAR DefaultCountry =
{
invalid,
UK,
Brazil,
Brazil,
UK,
India
};

/* from sheet2 car */

VAR const polo =
{

};

//need to crate hexa array for BMW,i20,Swift and wagnor

VAR DefaultCAR =
{
invalid,
BMW,
Swift,
Swift,
BMW,
Wagnor
}


excelsheet.txt format :



const exceldetails[Maxindex] = 
{
/* index 0 */
/* index 1 */
{
{ UK, India, brazil,eMaxNoOfcountry, eMaxNoOfcountry},
{BMW, Wagnor, Swift,eMaxNoOfcar,eMaxNoOfcar },
index1,
},
/*index 2*/
etc..
};




  1. If the column has "-" , it should take 0 value and if it is integer , it should take 1 value and print the hexa value and binary value both



    eg: for country index 0 : - - - - - => binary : 00000 => hexa : 0x0
    index 1 : - 1 - 3 2 => binary : 01011 => hexa : 0xB



    Array name : VAR const US,france etc.. VAR const polo,swift etc..




  2. If the column contain 1 , It is default value and print the default value column name for each index in array



    array name : VAR DefaultCountry,VAR DefaultCAR)




  3. Create another file "exceldetails.txt" and write the order of each country and car details in array . If "-" present take as eMaxNoOf.



    array name : exceldetails[Maxindex])




How to do this ? Any help ? Any Reference also be helpful . How to use one button for taking table values from multi tabs?










share|improve this question

























  • What exactly are you having problems with? Forgetting the button for now, can you do everything else?

    – Tim Williams
    Nov 15 '18 at 20:46











  • yes . i want to know how to traverse each tabs (sheets) tables

    – user2986042
    Nov 15 '18 at 21:15














-1












-1








-1


0






I am a beginner in VB script and I have a excel sheet with multi tab . I have created a one button inside one excel sheet . Another sheets having some table . I want to generate some code inside a file with those excel tables using a simple button .



For example :



This excel book have one tab called Generate . Inside Generate i have created one button .



enter image description here



I have another tab named country which contain a table for country list



enter image description here



I have another tab also named car which contain a table for car list



enter image description here



Now i want to create a file "output.txt" which should create with some code from both tabs (country and vehicle )when click Generate code button .



My output.txt format :



*from sheet1 Country*/

VAR const US =
{
0x0,/*binary 00000*/
0xB,/*binary 01011*/
0x3,/*binary 00011*/
0x3,/*binary 00011*/
0xB,/*binary 01011*/
1xB /*binary 11011*/
};

//need to crate hexa array for Uk,france,brazil and india

VAR DefaultCountry =
{
invalid,
UK,
Brazil,
Brazil,
UK,
India
};

/* from sheet2 car */

VAR const polo =
{

};

//need to crate hexa array for BMW,i20,Swift and wagnor

VAR DefaultCAR =
{
invalid,
BMW,
Swift,
Swift,
BMW,
Wagnor
}


excelsheet.txt format :



const exceldetails[Maxindex] = 
{
/* index 0 */
/* index 1 */
{
{ UK, India, brazil,eMaxNoOfcountry, eMaxNoOfcountry},
{BMW, Wagnor, Swift,eMaxNoOfcar,eMaxNoOfcar },
index1,
},
/*index 2*/
etc..
};




  1. If the column has "-" , it should take 0 value and if it is integer , it should take 1 value and print the hexa value and binary value both



    eg: for country index 0 : - - - - - => binary : 00000 => hexa : 0x0
    index 1 : - 1 - 3 2 => binary : 01011 => hexa : 0xB



    Array name : VAR const US,france etc.. VAR const polo,swift etc..




  2. If the column contain 1 , It is default value and print the default value column name for each index in array



    array name : VAR DefaultCountry,VAR DefaultCAR)




  3. Create another file "exceldetails.txt" and write the order of each country and car details in array . If "-" present take as eMaxNoOf.



    array name : exceldetails[Maxindex])




How to do this ? Any help ? Any Reference also be helpful . How to use one button for taking table values from multi tabs?










share|improve this question
















I am a beginner in VB script and I have a excel sheet with multi tab . I have created a one button inside one excel sheet . Another sheets having some table . I want to generate some code inside a file with those excel tables using a simple button .



For example :



This excel book have one tab called Generate . Inside Generate i have created one button .



enter image description here



I have another tab named country which contain a table for country list



enter image description here



I have another tab also named car which contain a table for car list



enter image description here



Now i want to create a file "output.txt" which should create with some code from both tabs (country and vehicle )when click Generate code button .



My output.txt format :



*from sheet1 Country*/

VAR const US =
{
0x0,/*binary 00000*/
0xB,/*binary 01011*/
0x3,/*binary 00011*/
0x3,/*binary 00011*/
0xB,/*binary 01011*/
1xB /*binary 11011*/
};

//need to crate hexa array for Uk,france,brazil and india

VAR DefaultCountry =
{
invalid,
UK,
Brazil,
Brazil,
UK,
India
};

/* from sheet2 car */

VAR const polo =
{

};

//need to crate hexa array for BMW,i20,Swift and wagnor

VAR DefaultCAR =
{
invalid,
BMW,
Swift,
Swift,
BMW,
Wagnor
}


excelsheet.txt format :



const exceldetails[Maxindex] = 
{
/* index 0 */
/* index 1 */
{
{ UK, India, brazil,eMaxNoOfcountry, eMaxNoOfcountry},
{BMW, Wagnor, Swift,eMaxNoOfcar,eMaxNoOfcar },
index1,
},
/*index 2*/
etc..
};




  1. If the column has "-" , it should take 0 value and if it is integer , it should take 1 value and print the hexa value and binary value both



    eg: for country index 0 : - - - - - => binary : 00000 => hexa : 0x0
    index 1 : - 1 - 3 2 => binary : 01011 => hexa : 0xB



    Array name : VAR const US,france etc.. VAR const polo,swift etc..




  2. If the column contain 1 , It is default value and print the default value column name for each index in array



    array name : VAR DefaultCountry,VAR DefaultCAR)




  3. Create another file "exceldetails.txt" and write the order of each country and car details in array . If "-" present take as eMaxNoOf.



    array name : exceldetails[Maxindex])




How to do this ? Any help ? Any Reference also be helpful . How to use one button for taking table values from multi tabs?







excel vba basic






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 19:10







user2986042

















asked Nov 15 '18 at 18:54









user2986042user2986042

426417




426417













  • What exactly are you having problems with? Forgetting the button for now, can you do everything else?

    – Tim Williams
    Nov 15 '18 at 20:46











  • yes . i want to know how to traverse each tabs (sheets) tables

    – user2986042
    Nov 15 '18 at 21:15



















  • What exactly are you having problems with? Forgetting the button for now, can you do everything else?

    – Tim Williams
    Nov 15 '18 at 20:46











  • yes . i want to know how to traverse each tabs (sheets) tables

    – user2986042
    Nov 15 '18 at 21:15

















What exactly are you having problems with? Forgetting the button for now, can you do everything else?

– Tim Williams
Nov 15 '18 at 20:46





What exactly are you having problems with? Forgetting the button for now, can you do everything else?

– Tim Williams
Nov 15 '18 at 20:46













yes . i want to know how to traverse each tabs (sheets) tables

– user2986042
Nov 15 '18 at 21:15





yes . i want to know how to traverse each tabs (sheets) tables

– user2986042
Nov 15 '18 at 21:15












1 Answer
1






active

oldest

votes


















1














I give you a little snippet code that doesn't answer all your question but only when you convert decimal value in binary and in hex. I don't understood good all what you want



Sub test()

'binary code and hex code
With Application.WorksheetFunction ' with this row you can use the functions Dec2Bin, Dec2Hex

'convert decimal in binary
Cells(1, 1) = .Dec2Bin(Cells(1, 2)) ' input 3 -> out: 11

'convert binary in hex
Cells(2, 1) = .Dec2Hex(Cells(2, 2)) ' input 11 -> out B

End With
End Sub


this is the snippet code where you can create and write into file txt



Sub test()
'create and write into file txt
'when you execute again the macro the file is overwritten
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim Fileout As Object
Set Fileout = fso.CreateTextFile("yourPathMyFile.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
End Sub


I created two macro so you can try every single macro. You have to create an only macro where there is all the code...



hope this helps



EDIT to answer your commento
If you want work into sheet below there is an example



Sub test()

Dim sh1, sh2 As Worksheet
Dim i, r, numRows, numColumns As Long

'set sh1 and the works it
Set sh1 = Sheets("Country") ' sheet name

'count how many rows there are into sheet1
'numRows = sh1.Range("A:A").Cells.SpecialCells(xlCellTypeContants).Count
numRows = sh1.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet1
numColumns = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh1
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

'----repeat operation for the sheet2
'set sh2 and the works it
Set sh2 = Sheets("car") ' sheet name

'count how many rows there are into sheet2
numRows = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet2
numColumns = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh2
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

End Sub


There are two for loop because One use the columns and the other the rows...






share|improve this answer


























  • Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

    – user2986042
    Nov 15 '18 at 21:16











  • @user2986042 i have edited my answer and i hope this helps

    – Ferdinando
    Nov 16 '18 at 13:00













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%2f53326178%2fhow-to-do-single-button-action-for-multi-sheet-tabs-excel-using-vb-script%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









1














I give you a little snippet code that doesn't answer all your question but only when you convert decimal value in binary and in hex. I don't understood good all what you want



Sub test()

'binary code and hex code
With Application.WorksheetFunction ' with this row you can use the functions Dec2Bin, Dec2Hex

'convert decimal in binary
Cells(1, 1) = .Dec2Bin(Cells(1, 2)) ' input 3 -> out: 11

'convert binary in hex
Cells(2, 1) = .Dec2Hex(Cells(2, 2)) ' input 11 -> out B

End With
End Sub


this is the snippet code where you can create and write into file txt



Sub test()
'create and write into file txt
'when you execute again the macro the file is overwritten
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim Fileout As Object
Set Fileout = fso.CreateTextFile("yourPathMyFile.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
End Sub


I created two macro so you can try every single macro. You have to create an only macro where there is all the code...



hope this helps



EDIT to answer your commento
If you want work into sheet below there is an example



Sub test()

Dim sh1, sh2 As Worksheet
Dim i, r, numRows, numColumns As Long

'set sh1 and the works it
Set sh1 = Sheets("Country") ' sheet name

'count how many rows there are into sheet1
'numRows = sh1.Range("A:A").Cells.SpecialCells(xlCellTypeContants).Count
numRows = sh1.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet1
numColumns = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh1
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

'----repeat operation for the sheet2
'set sh2 and the works it
Set sh2 = Sheets("car") ' sheet name

'count how many rows there are into sheet2
numRows = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet2
numColumns = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh2
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

End Sub


There are two for loop because One use the columns and the other the rows...






share|improve this answer


























  • Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

    – user2986042
    Nov 15 '18 at 21:16











  • @user2986042 i have edited my answer and i hope this helps

    – Ferdinando
    Nov 16 '18 at 13:00


















1














I give you a little snippet code that doesn't answer all your question but only when you convert decimal value in binary and in hex. I don't understood good all what you want



Sub test()

'binary code and hex code
With Application.WorksheetFunction ' with this row you can use the functions Dec2Bin, Dec2Hex

'convert decimal in binary
Cells(1, 1) = .Dec2Bin(Cells(1, 2)) ' input 3 -> out: 11

'convert binary in hex
Cells(2, 1) = .Dec2Hex(Cells(2, 2)) ' input 11 -> out B

End With
End Sub


this is the snippet code where you can create and write into file txt



Sub test()
'create and write into file txt
'when you execute again the macro the file is overwritten
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim Fileout As Object
Set Fileout = fso.CreateTextFile("yourPathMyFile.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
End Sub


I created two macro so you can try every single macro. You have to create an only macro where there is all the code...



hope this helps



EDIT to answer your commento
If you want work into sheet below there is an example



Sub test()

Dim sh1, sh2 As Worksheet
Dim i, r, numRows, numColumns As Long

'set sh1 and the works it
Set sh1 = Sheets("Country") ' sheet name

'count how many rows there are into sheet1
'numRows = sh1.Range("A:A").Cells.SpecialCells(xlCellTypeContants).Count
numRows = sh1.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet1
numColumns = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh1
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

'----repeat operation for the sheet2
'set sh2 and the works it
Set sh2 = Sheets("car") ' sheet name

'count how many rows there are into sheet2
numRows = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet2
numColumns = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh2
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

End Sub


There are two for loop because One use the columns and the other the rows...






share|improve this answer


























  • Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

    – user2986042
    Nov 15 '18 at 21:16











  • @user2986042 i have edited my answer and i hope this helps

    – Ferdinando
    Nov 16 '18 at 13:00
















1












1








1







I give you a little snippet code that doesn't answer all your question but only when you convert decimal value in binary and in hex. I don't understood good all what you want



Sub test()

'binary code and hex code
With Application.WorksheetFunction ' with this row you can use the functions Dec2Bin, Dec2Hex

'convert decimal in binary
Cells(1, 1) = .Dec2Bin(Cells(1, 2)) ' input 3 -> out: 11

'convert binary in hex
Cells(2, 1) = .Dec2Hex(Cells(2, 2)) ' input 11 -> out B

End With
End Sub


this is the snippet code where you can create and write into file txt



Sub test()
'create and write into file txt
'when you execute again the macro the file is overwritten
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim Fileout As Object
Set Fileout = fso.CreateTextFile("yourPathMyFile.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
End Sub


I created two macro so you can try every single macro. You have to create an only macro where there is all the code...



hope this helps



EDIT to answer your commento
If you want work into sheet below there is an example



Sub test()

Dim sh1, sh2 As Worksheet
Dim i, r, numRows, numColumns As Long

'set sh1 and the works it
Set sh1 = Sheets("Country") ' sheet name

'count how many rows there are into sheet1
'numRows = sh1.Range("A:A").Cells.SpecialCells(xlCellTypeContants).Count
numRows = sh1.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet1
numColumns = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh1
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

'----repeat operation for the sheet2
'set sh2 and the works it
Set sh2 = Sheets("car") ' sheet name

'count how many rows there are into sheet2
numRows = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet2
numColumns = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh2
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

End Sub


There are two for loop because One use the columns and the other the rows...






share|improve this answer















I give you a little snippet code that doesn't answer all your question but only when you convert decimal value in binary and in hex. I don't understood good all what you want



Sub test()

'binary code and hex code
With Application.WorksheetFunction ' with this row you can use the functions Dec2Bin, Dec2Hex

'convert decimal in binary
Cells(1, 1) = .Dec2Bin(Cells(1, 2)) ' input 3 -> out: 11

'convert binary in hex
Cells(2, 1) = .Dec2Hex(Cells(2, 2)) ' input 11 -> out B

End With
End Sub


this is the snippet code where you can create and write into file txt



Sub test()
'create and write into file txt
'when you execute again the macro the file is overwritten
Dim fso As Object

Set fso = CreateObject("Scripting.FileSystemObject")

Dim Fileout As Object
Set Fileout = fso.CreateTextFile("yourPathMyFile.txt", True, True)
Fileout.Write "your string goes here"
Fileout.Close
End Sub


I created two macro so you can try every single macro. You have to create an only macro where there is all the code...



hope this helps



EDIT to answer your commento
If you want work into sheet below there is an example



Sub test()

Dim sh1, sh2 As Worksheet
Dim i, r, numRows, numColumns As Long

'set sh1 and the works it
Set sh1 = Sheets("Country") ' sheet name

'count how many rows there are into sheet1
'numRows = sh1.Range("A:A").Cells.SpecialCells(xlCellTypeContants).Count
numRows = sh1.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet1
numColumns = sh1.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh1
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

'----repeat operation for the sheet2
'set sh2 and the works it
Set sh2 = Sheets("car") ' sheet name

'count how many rows there are into sheet2
numRows = sh2.Cells(Rows.Count, 1).End(xlUp).Row
'MsgBox numRows

'count how many columns there are into sheet2
numColumns = sh2.Cells(1, Columns.Count).End(xlToLeft).Column
'MsgBox numColumns

With sh2
For j = 2 To numColumns
For i = 2 To numRows - 1
If .Cells(i, j) = "-" Then

'msgbox "the item into cell is empity: "
'you code..
Else
'msgbox "the item into cells is: " & .cells(i,j)
'your code...

End If
Next i
Next j
End With

End Sub


There are two for loop because One use the columns and the other the rows...







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 16 '18 at 9:37

























answered Nov 15 '18 at 20:49









FerdinandoFerdinando

5891518




5891518













  • Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

    – user2986042
    Nov 15 '18 at 21:16











  • @user2986042 i have edited my answer and i hope this helps

    – Ferdinando
    Nov 16 '18 at 13:00





















  • Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

    – user2986042
    Nov 15 '18 at 21:16











  • @user2986042 i have edited my answer and i hope this helps

    – Ferdinando
    Nov 16 '18 at 13:00



















Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

– user2986042
Nov 15 '18 at 21:16





Thanks for your answer . could you please explain how to get data from each traverse each tabs (sheets) tables . fo example in my case , country and car are the tabs (sheets) contain tables .

– user2986042
Nov 15 '18 at 21:16













@user2986042 i have edited my answer and i hope this helps

– Ferdinando
Nov 16 '18 at 13:00







@user2986042 i have edited my answer and i hope this helps

– Ferdinando
Nov 16 '18 at 13:00






















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%2f53326178%2fhow-to-do-single-button-action-for-multi-sheet-tabs-excel-using-vb-script%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

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python