VBScript for splitting rows by cartesian product












-1














I have an Excel file which is generated by another program.
I need to split and extract the Excel rows in that way:



the source:



enter image description here



the Excel after the "split" action should be:



enter image description here



the way to do this is clear for me- but I didn't manage to write it in VB
the logic should be:
we have 3 columns: name, servers, accounts -> the results will contain a cartesian product of servers X accounts for each 'name'.



int Count1=1 loop for counting the number of column B (servers-separated by comma)
int Count2=1 loop for counting the number of column C (accounts-separated by comma)

1 loop i=1 from i to count1(servers)

for each server
loop: j=1 from j to count2(account)
create a new row(column A:=Name, column B:=server[i],coulmn c:=account[j])

move to next row


I just need help with syntax.










share|improve this question




















  • 1




    Try using this answer as an example of the syntax required: stackoverflow.com/questions/52264996/…
    – Techno Dabbler
    Nov 19 at 23:01






  • 2




    I would suggest the following: Decide which language you want to use (VBScript or VBA). Immerse yourself in a tutorial for that language. Record the basic operations outlined in your pseudocode as one or more macro(s). Edit the macro(s) to form the desired end result. In that order.
    – Ansgar Wiechers
    Nov 20 at 0:02
















-1














I have an Excel file which is generated by another program.
I need to split and extract the Excel rows in that way:



the source:



enter image description here



the Excel after the "split" action should be:



enter image description here



the way to do this is clear for me- but I didn't manage to write it in VB
the logic should be:
we have 3 columns: name, servers, accounts -> the results will contain a cartesian product of servers X accounts for each 'name'.



int Count1=1 loop for counting the number of column B (servers-separated by comma)
int Count2=1 loop for counting the number of column C (accounts-separated by comma)

1 loop i=1 from i to count1(servers)

for each server
loop: j=1 from j to count2(account)
create a new row(column A:=Name, column B:=server[i],coulmn c:=account[j])

move to next row


I just need help with syntax.










share|improve this question




















  • 1




    Try using this answer as an example of the syntax required: stackoverflow.com/questions/52264996/…
    – Techno Dabbler
    Nov 19 at 23:01






  • 2




    I would suggest the following: Decide which language you want to use (VBScript or VBA). Immerse yourself in a tutorial for that language. Record the basic operations outlined in your pseudocode as one or more macro(s). Edit the macro(s) to form the desired end result. In that order.
    – Ansgar Wiechers
    Nov 20 at 0:02














-1












-1








-1







I have an Excel file which is generated by another program.
I need to split and extract the Excel rows in that way:



the source:



enter image description here



the Excel after the "split" action should be:



enter image description here



the way to do this is clear for me- but I didn't manage to write it in VB
the logic should be:
we have 3 columns: name, servers, accounts -> the results will contain a cartesian product of servers X accounts for each 'name'.



int Count1=1 loop for counting the number of column B (servers-separated by comma)
int Count2=1 loop for counting the number of column C (accounts-separated by comma)

1 loop i=1 from i to count1(servers)

for each server
loop: j=1 from j to count2(account)
create a new row(column A:=Name, column B:=server[i],coulmn c:=account[j])

move to next row


I just need help with syntax.










share|improve this question















I have an Excel file which is generated by another program.
I need to split and extract the Excel rows in that way:



the source:



enter image description here



the Excel after the "split" action should be:



enter image description here



the way to do this is clear for me- but I didn't manage to write it in VB
the logic should be:
we have 3 columns: name, servers, accounts -> the results will contain a cartesian product of servers X accounts for each 'name'.



int Count1=1 loop for counting the number of column B (servers-separated by comma)
int Count2=1 loop for counting the number of column C (accounts-separated by comma)

1 loop i=1 from i to count1(servers)

for each server
loop: j=1 from j to count2(account)
create a new row(column A:=Name, column B:=server[i],coulmn c:=account[j])

move to next row


I just need help with syntax.







excel vba excel-vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 8:06









Lankymart

11.5k438100




11.5k438100










asked Nov 19 at 21:30









Racheli Soffer

1




1








  • 1




    Try using this answer as an example of the syntax required: stackoverflow.com/questions/52264996/…
    – Techno Dabbler
    Nov 19 at 23:01






  • 2




    I would suggest the following: Decide which language you want to use (VBScript or VBA). Immerse yourself in a tutorial for that language. Record the basic operations outlined in your pseudocode as one or more macro(s). Edit the macro(s) to form the desired end result. In that order.
    – Ansgar Wiechers
    Nov 20 at 0:02














  • 1




    Try using this answer as an example of the syntax required: stackoverflow.com/questions/52264996/…
    – Techno Dabbler
    Nov 19 at 23:01






  • 2




    I would suggest the following: Decide which language you want to use (VBScript or VBA). Immerse yourself in a tutorial for that language. Record the basic operations outlined in your pseudocode as one or more macro(s). Edit the macro(s) to form the desired end result. In that order.
    – Ansgar Wiechers
    Nov 20 at 0:02








1




1




Try using this answer as an example of the syntax required: stackoverflow.com/questions/52264996/…
– Techno Dabbler
Nov 19 at 23:01




Try using this answer as an example of the syntax required: stackoverflow.com/questions/52264996/…
– Techno Dabbler
Nov 19 at 23:01




2




2




I would suggest the following: Decide which language you want to use (VBScript or VBA). Immerse yourself in a tutorial for that language. Record the basic operations outlined in your pseudocode as one or more macro(s). Edit the macro(s) to form the desired end result. In that order.
– Ansgar Wiechers
Nov 20 at 0:02




I would suggest the following: Decide which language you want to use (VBScript or VBA). Immerse yourself in a tutorial for that language. Record the basic operations outlined in your pseudocode as one or more macro(s). Edit the macro(s) to form the desired end result. In that order.
– Ansgar Wiechers
Nov 20 at 0:02












1 Answer
1






active

oldest

votes


















1














Try,



Sub test()
Dim vDB, vR(), vS(1 To 2), s
Dim i As Long, j As Integer, n As Long
Dim c1 As Integer, c2 As Integer

vDB = Range("a1").CurrentRegion

For i = 1 To UBound(vDB, 1)
vS(1) = Split(vDB(i, 2), ",")
vS(2) = Split(vDB(i, 3), ",")
If InStr(vDB(i, 2), ",") Then
c1 = 1
c2 = 2
Else
c1 = 2
c2 = 1
End If

For Each s In vS(c1)
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
vR(1, n) = vDB(i, 1)
vR(c1 + 1, n) = s
vR(c2 + 1, n) = vS(c2)(0)
Next s
Next i
Sheets.Add
Range("a1").Resize(n, 3) = WorksheetFunction.Transpose(vR)

End Sub





share|improve this answer





















  • Thanks!i will try and update
    – Racheli Soffer
    Nov 20 at 10:56










  • Perfect! thanks :)
    – Racheli Soffer
    Nov 20 at 11:17











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%2f53382924%2fvbscript-for-splitting-rows-by-cartesian-product%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














Try,



Sub test()
Dim vDB, vR(), vS(1 To 2), s
Dim i As Long, j As Integer, n As Long
Dim c1 As Integer, c2 As Integer

vDB = Range("a1").CurrentRegion

For i = 1 To UBound(vDB, 1)
vS(1) = Split(vDB(i, 2), ",")
vS(2) = Split(vDB(i, 3), ",")
If InStr(vDB(i, 2), ",") Then
c1 = 1
c2 = 2
Else
c1 = 2
c2 = 1
End If

For Each s In vS(c1)
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
vR(1, n) = vDB(i, 1)
vR(c1 + 1, n) = s
vR(c2 + 1, n) = vS(c2)(0)
Next s
Next i
Sheets.Add
Range("a1").Resize(n, 3) = WorksheetFunction.Transpose(vR)

End Sub





share|improve this answer





















  • Thanks!i will try and update
    – Racheli Soffer
    Nov 20 at 10:56










  • Perfect! thanks :)
    – Racheli Soffer
    Nov 20 at 11:17
















1














Try,



Sub test()
Dim vDB, vR(), vS(1 To 2), s
Dim i As Long, j As Integer, n As Long
Dim c1 As Integer, c2 As Integer

vDB = Range("a1").CurrentRegion

For i = 1 To UBound(vDB, 1)
vS(1) = Split(vDB(i, 2), ",")
vS(2) = Split(vDB(i, 3), ",")
If InStr(vDB(i, 2), ",") Then
c1 = 1
c2 = 2
Else
c1 = 2
c2 = 1
End If

For Each s In vS(c1)
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
vR(1, n) = vDB(i, 1)
vR(c1 + 1, n) = s
vR(c2 + 1, n) = vS(c2)(0)
Next s
Next i
Sheets.Add
Range("a1").Resize(n, 3) = WorksheetFunction.Transpose(vR)

End Sub





share|improve this answer





















  • Thanks!i will try and update
    – Racheli Soffer
    Nov 20 at 10:56










  • Perfect! thanks :)
    – Racheli Soffer
    Nov 20 at 11:17














1












1








1






Try,



Sub test()
Dim vDB, vR(), vS(1 To 2), s
Dim i As Long, j As Integer, n As Long
Dim c1 As Integer, c2 As Integer

vDB = Range("a1").CurrentRegion

For i = 1 To UBound(vDB, 1)
vS(1) = Split(vDB(i, 2), ",")
vS(2) = Split(vDB(i, 3), ",")
If InStr(vDB(i, 2), ",") Then
c1 = 1
c2 = 2
Else
c1 = 2
c2 = 1
End If

For Each s In vS(c1)
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
vR(1, n) = vDB(i, 1)
vR(c1 + 1, n) = s
vR(c2 + 1, n) = vS(c2)(0)
Next s
Next i
Sheets.Add
Range("a1").Resize(n, 3) = WorksheetFunction.Transpose(vR)

End Sub





share|improve this answer












Try,



Sub test()
Dim vDB, vR(), vS(1 To 2), s
Dim i As Long, j As Integer, n As Long
Dim c1 As Integer, c2 As Integer

vDB = Range("a1").CurrentRegion

For i = 1 To UBound(vDB, 1)
vS(1) = Split(vDB(i, 2), ",")
vS(2) = Split(vDB(i, 3), ",")
If InStr(vDB(i, 2), ",") Then
c1 = 1
c2 = 2
Else
c1 = 2
c2 = 1
End If

For Each s In vS(c1)
n = n + 1
ReDim Preserve vR(1 To 3, 1 To n)
vR(1, n) = vDB(i, 1)
vR(c1 + 1, n) = s
vR(c2 + 1, n) = vS(c2)(0)
Next s
Next i
Sheets.Add
Range("a1").Resize(n, 3) = WorksheetFunction.Transpose(vR)

End Sub






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 0:13









Dy.Lee

3,265159




3,265159












  • Thanks!i will try and update
    – Racheli Soffer
    Nov 20 at 10:56










  • Perfect! thanks :)
    – Racheli Soffer
    Nov 20 at 11:17


















  • Thanks!i will try and update
    – Racheli Soffer
    Nov 20 at 10:56










  • Perfect! thanks :)
    – Racheli Soffer
    Nov 20 at 11:17
















Thanks!i will try and update
– Racheli Soffer
Nov 20 at 10:56




Thanks!i will try and update
– Racheli Soffer
Nov 20 at 10:56












Perfect! thanks :)
– Racheli Soffer
Nov 20 at 11:17




Perfect! thanks :)
– Racheli Soffer
Nov 20 at 11:17


















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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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%2f53382924%2fvbscript-for-splitting-rows-by-cartesian-product%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

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?