How to sort rows in a excel sheet and print to a file using VB script?
I have a table named student . I am trying to print corresponding student names with respect to his mark . I want to print to a file using Excel macro .
My table which contain title as student name 1 , 2, 3 etc.. and corresponding marks as 1 , 2, 3 ,4 and "-" .

I want to write function in VB to sort corresponding rows as each subject (0,1,2,3,...7) and also print the values to a file .
output (file.txt)
NULL,NULL,NULL,NULL,NULL
STUDENT 2 ,STUDENT 5 ,STUDENT 4 ,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
etc..
columns in a row should sort to ascending order and if "-" present in any column should be print as NULL as remaining values .
I have written
Sub test()
'create and write into file txt
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("MyFile.txt", True, True)
'Write logic for sorting
Fileout.Close
End Sub
How to sort in a excel using VB script and print those rows ?
excel vba excel-vba
add a comment |
I have a table named student . I am trying to print corresponding student names with respect to his mark . I want to print to a file using Excel macro .
My table which contain title as student name 1 , 2, 3 etc.. and corresponding marks as 1 , 2, 3 ,4 and "-" .

I want to write function in VB to sort corresponding rows as each subject (0,1,2,3,...7) and also print the values to a file .
output (file.txt)
NULL,NULL,NULL,NULL,NULL
STUDENT 2 ,STUDENT 5 ,STUDENT 4 ,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
etc..
columns in a row should sort to ascending order and if "-" present in any column should be print as NULL as remaining values .
I have written
Sub test()
'create and write into file txt
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("MyFile.txt", True, True)
'Write logic for sorting
Fileout.Close
End Sub
How to sort in a excel using VB script and print those rows ?
excel vba excel-vba
3
Do you want VBScript or VBA? They are not the same thing
– cybernetic.nomad
Nov 23 '18 at 17:42
VB script for excel
– user2986042
Nov 23 '18 at 19:00
Since you mention Excel Macro, and your example code is VBA I'm going to assume yo mean VBA and not VBScript. You can revert it if this is not the case.
– Geert Bellekens
Nov 24 '18 at 6:58
add a comment |
I have a table named student . I am trying to print corresponding student names with respect to his mark . I want to print to a file using Excel macro .
My table which contain title as student name 1 , 2, 3 etc.. and corresponding marks as 1 , 2, 3 ,4 and "-" .

I want to write function in VB to sort corresponding rows as each subject (0,1,2,3,...7) and also print the values to a file .
output (file.txt)
NULL,NULL,NULL,NULL,NULL
STUDENT 2 ,STUDENT 5 ,STUDENT 4 ,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
etc..
columns in a row should sort to ascending order and if "-" present in any column should be print as NULL as remaining values .
I have written
Sub test()
'create and write into file txt
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("MyFile.txt", True, True)
'Write logic for sorting
Fileout.Close
End Sub
How to sort in a excel using VB script and print those rows ?
excel vba excel-vba
I have a table named student . I am trying to print corresponding student names with respect to his mark . I want to print to a file using Excel macro .
My table which contain title as student name 1 , 2, 3 etc.. and corresponding marks as 1 , 2, 3 ,4 and "-" .

I want to write function in VB to sort corresponding rows as each subject (0,1,2,3,...7) and also print the values to a file .
output (file.txt)
NULL,NULL,NULL,NULL,NULL
STUDENT 2 ,STUDENT 5 ,STUDENT 4 ,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
etc..
columns in a row should sort to ascending order and if "-" present in any column should be print as NULL as remaining values .
I have written
Sub test()
'create and write into file txt
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim Fileout As Object
Set Fileout = fso.CreateTextFile("MyFile.txt", True, True)
'Write logic for sorting
Fileout.Close
End Sub
How to sort in a excel using VB script and print those rows ?
excel vba excel-vba
excel vba excel-vba
edited Nov 26 '18 at 7:27
Pᴇʜ
22.8k62850
22.8k62850
asked Nov 23 '18 at 17:36
user2986042user2986042
415316
415316
3
Do you want VBScript or VBA? They are not the same thing
– cybernetic.nomad
Nov 23 '18 at 17:42
VB script for excel
– user2986042
Nov 23 '18 at 19:00
Since you mention Excel Macro, and your example code is VBA I'm going to assume yo mean VBA and not VBScript. You can revert it if this is not the case.
– Geert Bellekens
Nov 24 '18 at 6:58
add a comment |
3
Do you want VBScript or VBA? They are not the same thing
– cybernetic.nomad
Nov 23 '18 at 17:42
VB script for excel
– user2986042
Nov 23 '18 at 19:00
Since you mention Excel Macro, and your example code is VBA I'm going to assume yo mean VBA and not VBScript. You can revert it if this is not the case.
– Geert Bellekens
Nov 24 '18 at 6:58
3
3
Do you want VBScript or VBA? They are not the same thing
– cybernetic.nomad
Nov 23 '18 at 17:42
Do you want VBScript or VBA? They are not the same thing
– cybernetic.nomad
Nov 23 '18 at 17:42
VB script for excel
– user2986042
Nov 23 '18 at 19:00
VB script for excel
– user2986042
Nov 23 '18 at 19:00
Since you mention Excel Macro, and your example code is VBA I'm going to assume yo mean VBA and not VBScript. You can revert it if this is not the case.
– Geert Bellekens
Nov 24 '18 at 6:58
Since you mention Excel Macro, and your example code is VBA I'm going to assume yo mean VBA and not VBScript. You can revert it if this is not the case.
– Geert Bellekens
Nov 24 '18 at 6:58
add a comment |
1 Answer
1
active
oldest
votes
Here is a way of implementing that, adapt it to your needs:
' Naive O(N^2) sort
Sub Sort(arr() As Long, students() As String)
If UBound(arr) <= 1 Then Exit Sub
Dim i As Long, j As Long
For i = 0 To UBound(arr) - 1
' Look for the minimum index in the sub-array going from i
Dim indexOfMin As Long
indexOfMin = i
For j = i To UBound(arr)
If arr(j) < arr(indexOfMin) Then
indexOfMin = j
End If
Next j
' Put the minimum mark at the beginning of the sub-array
Dim tmp As Variant
tmp = arr(i)
arr(i) = arr(indexOfMin)
arr(indexOfMin) = tmp
' Put the student with the minimum value at the beginning of the students sub-array
tmp = students(i)
students(i) = students(indexOfMin)
students(indexOfMin) = tmp
Next i
End Sub
Sub SortAndSave()
Dim dataRange As Range
Set dataRange = Range("A1:F9")
Dim data As Variant
data = dataRange.Value
Dim NSubject As Long, NStudents As Long
NSubject = UBound(data, 1) - 1
NStudents = UBound(data, 2) - 1
Dim text As String
Dim i As Long, j As Long
For i = 1 To NSubject
' Read marks and students names
Dim subjectMarks() As Long
ReDim subjectMarks(0 To NStudents - 1)
Dim students() As String
ReDim students(0 To NStudents - 1)
For j = 1 To NStudents
' Use a big enough number 999 so that students with no mark will be pushed to the end
subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999)
students(j - 1) = data(1, j + 1)
Next j
' Sort marks and students
Sort subjectMarks, students
' Build display row for subject
Dim row As String
row = ""
For j = 1 To NStudents
' If there is a mark render the student name
If subjectMarks(j - 1) <> 999 Then
row = row & students(j - 1)
' Otherwise render NULL
Else
row = row & "NULL"
End If
' Add a comma if not the latest
If j <> NStudents Then
row = row & ","
End If
Next j
text = text & row
' Add a rn if not the latest
If i <> NSubject Then
text = text & vbCrLf
End If
Next i
End Sub
Result:
NULL,NULL,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
1
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@user2986042 You probably have a wrong value in your data range, i.e. which is neither-or an integer.
– Pragmateek
Nov 26 '18 at 10:00
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450932%2fhow-to-sort-rows-in-a-excel-sheet-and-print-to-a-file-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
Here is a way of implementing that, adapt it to your needs:
' Naive O(N^2) sort
Sub Sort(arr() As Long, students() As String)
If UBound(arr) <= 1 Then Exit Sub
Dim i As Long, j As Long
For i = 0 To UBound(arr) - 1
' Look for the minimum index in the sub-array going from i
Dim indexOfMin As Long
indexOfMin = i
For j = i To UBound(arr)
If arr(j) < arr(indexOfMin) Then
indexOfMin = j
End If
Next j
' Put the minimum mark at the beginning of the sub-array
Dim tmp As Variant
tmp = arr(i)
arr(i) = arr(indexOfMin)
arr(indexOfMin) = tmp
' Put the student with the minimum value at the beginning of the students sub-array
tmp = students(i)
students(i) = students(indexOfMin)
students(indexOfMin) = tmp
Next i
End Sub
Sub SortAndSave()
Dim dataRange As Range
Set dataRange = Range("A1:F9")
Dim data As Variant
data = dataRange.Value
Dim NSubject As Long, NStudents As Long
NSubject = UBound(data, 1) - 1
NStudents = UBound(data, 2) - 1
Dim text As String
Dim i As Long, j As Long
For i = 1 To NSubject
' Read marks and students names
Dim subjectMarks() As Long
ReDim subjectMarks(0 To NStudents - 1)
Dim students() As String
ReDim students(0 To NStudents - 1)
For j = 1 To NStudents
' Use a big enough number 999 so that students with no mark will be pushed to the end
subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999)
students(j - 1) = data(1, j + 1)
Next j
' Sort marks and students
Sort subjectMarks, students
' Build display row for subject
Dim row As String
row = ""
For j = 1 To NStudents
' If there is a mark render the student name
If subjectMarks(j - 1) <> 999 Then
row = row & students(j - 1)
' Otherwise render NULL
Else
row = row & "NULL"
End If
' Add a comma if not the latest
If j <> NStudents Then
row = row & ","
End If
Next j
text = text & row
' Add a rn if not the latest
If i <> NSubject Then
text = text & vbCrLf
End If
Next i
End Sub
Result:
NULL,NULL,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
1
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@user2986042 You probably have a wrong value in your data range, i.e. which is neither-or an integer.
– Pragmateek
Nov 26 '18 at 10:00
add a comment |
Here is a way of implementing that, adapt it to your needs:
' Naive O(N^2) sort
Sub Sort(arr() As Long, students() As String)
If UBound(arr) <= 1 Then Exit Sub
Dim i As Long, j As Long
For i = 0 To UBound(arr) - 1
' Look for the minimum index in the sub-array going from i
Dim indexOfMin As Long
indexOfMin = i
For j = i To UBound(arr)
If arr(j) < arr(indexOfMin) Then
indexOfMin = j
End If
Next j
' Put the minimum mark at the beginning of the sub-array
Dim tmp As Variant
tmp = arr(i)
arr(i) = arr(indexOfMin)
arr(indexOfMin) = tmp
' Put the student with the minimum value at the beginning of the students sub-array
tmp = students(i)
students(i) = students(indexOfMin)
students(indexOfMin) = tmp
Next i
End Sub
Sub SortAndSave()
Dim dataRange As Range
Set dataRange = Range("A1:F9")
Dim data As Variant
data = dataRange.Value
Dim NSubject As Long, NStudents As Long
NSubject = UBound(data, 1) - 1
NStudents = UBound(data, 2) - 1
Dim text As String
Dim i As Long, j As Long
For i = 1 To NSubject
' Read marks and students names
Dim subjectMarks() As Long
ReDim subjectMarks(0 To NStudents - 1)
Dim students() As String
ReDim students(0 To NStudents - 1)
For j = 1 To NStudents
' Use a big enough number 999 so that students with no mark will be pushed to the end
subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999)
students(j - 1) = data(1, j + 1)
Next j
' Sort marks and students
Sort subjectMarks, students
' Build display row for subject
Dim row As String
row = ""
For j = 1 To NStudents
' If there is a mark render the student name
If subjectMarks(j - 1) <> 999 Then
row = row & students(j - 1)
' Otherwise render NULL
Else
row = row & "NULL"
End If
' Add a comma if not the latest
If j <> NStudents Then
row = row & ","
End If
Next j
text = text & row
' Add a rn if not the latest
If i <> NSubject Then
text = text & vbCrLf
End If
Next i
End Sub
Result:
NULL,NULL,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
1
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@user2986042 You probably have a wrong value in your data range, i.e. which is neither-or an integer.
– Pragmateek
Nov 26 '18 at 10:00
add a comment |
Here is a way of implementing that, adapt it to your needs:
' Naive O(N^2) sort
Sub Sort(arr() As Long, students() As String)
If UBound(arr) <= 1 Then Exit Sub
Dim i As Long, j As Long
For i = 0 To UBound(arr) - 1
' Look for the minimum index in the sub-array going from i
Dim indexOfMin As Long
indexOfMin = i
For j = i To UBound(arr)
If arr(j) < arr(indexOfMin) Then
indexOfMin = j
End If
Next j
' Put the minimum mark at the beginning of the sub-array
Dim tmp As Variant
tmp = arr(i)
arr(i) = arr(indexOfMin)
arr(indexOfMin) = tmp
' Put the student with the minimum value at the beginning of the students sub-array
tmp = students(i)
students(i) = students(indexOfMin)
students(indexOfMin) = tmp
Next i
End Sub
Sub SortAndSave()
Dim dataRange As Range
Set dataRange = Range("A1:F9")
Dim data As Variant
data = dataRange.Value
Dim NSubject As Long, NStudents As Long
NSubject = UBound(data, 1) - 1
NStudents = UBound(data, 2) - 1
Dim text As String
Dim i As Long, j As Long
For i = 1 To NSubject
' Read marks and students names
Dim subjectMarks() As Long
ReDim subjectMarks(0 To NStudents - 1)
Dim students() As String
ReDim students(0 To NStudents - 1)
For j = 1 To NStudents
' Use a big enough number 999 so that students with no mark will be pushed to the end
subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999)
students(j - 1) = data(1, j + 1)
Next j
' Sort marks and students
Sort subjectMarks, students
' Build display row for subject
Dim row As String
row = ""
For j = 1 To NStudents
' If there is a mark render the student name
If subjectMarks(j - 1) <> 999 Then
row = row & students(j - 1)
' Otherwise render NULL
Else
row = row & "NULL"
End If
' Add a comma if not the latest
If j <> NStudents Then
row = row & ","
End If
Next j
text = text & row
' Add a rn if not the latest
If i <> NSubject Then
text = text & vbCrLf
End If
Next i
End Sub
Result:
NULL,NULL,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
Here is a way of implementing that, adapt it to your needs:
' Naive O(N^2) sort
Sub Sort(arr() As Long, students() As String)
If UBound(arr) <= 1 Then Exit Sub
Dim i As Long, j As Long
For i = 0 To UBound(arr) - 1
' Look for the minimum index in the sub-array going from i
Dim indexOfMin As Long
indexOfMin = i
For j = i To UBound(arr)
If arr(j) < arr(indexOfMin) Then
indexOfMin = j
End If
Next j
' Put the minimum mark at the beginning of the sub-array
Dim tmp As Variant
tmp = arr(i)
arr(i) = arr(indexOfMin)
arr(indexOfMin) = tmp
' Put the student with the minimum value at the beginning of the students sub-array
tmp = students(i)
students(i) = students(indexOfMin)
students(indexOfMin) = tmp
Next i
End Sub
Sub SortAndSave()
Dim dataRange As Range
Set dataRange = Range("A1:F9")
Dim data As Variant
data = dataRange.Value
Dim NSubject As Long, NStudents As Long
NSubject = UBound(data, 1) - 1
NStudents = UBound(data, 2) - 1
Dim text As String
Dim i As Long, j As Long
For i = 1 To NSubject
' Read marks and students names
Dim subjectMarks() As Long
ReDim subjectMarks(0 To NStudents - 1)
Dim students() As String
ReDim students(0 To NStudents - 1)
For j = 1 To NStudents
' Use a big enough number 999 so that students with no mark will be pushed to the end
subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999)
students(j - 1) = data(1, j + 1)
Next j
' Sort marks and students
Sort subjectMarks, students
' Build display row for subject
Dim row As String
row = ""
For j = 1 To NStudents
' If there is a mark render the student name
If subjectMarks(j - 1) <> 999 Then
row = row & students(j - 1)
' Otherwise render NULL
Else
row = row & "NULL"
End If
' Add a comma if not the latest
If j <> NStudents Then
row = row & ","
End If
Next j
text = text & row
' Add a rn if not the latest
If i <> NSubject Then
text = text & vbCrLf
End If
Next i
End Sub
Result:
NULL,NULL,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
STUDENT 2,STUDENT 5,STUDENT 4,NULL,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 5,STUDENT 4,STUDENT 2,STUDENT 1,NULL
STUDENT 4,STUDENT 5,NULL,NULL,NULL
answered Nov 23 '18 at 19:34
PragmateekPragmateek
9,25685488
9,25685488
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
1
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@user2986042 You probably have a wrong value in your data range, i.e. which is neither-or an integer.
– Pragmateek
Nov 26 '18 at 10:00
add a comment |
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
1
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@user2986042 You probably have a wrong value in your data range, i.e. which is neither-or an integer.
– Pragmateek
Nov 26 '18 at 10:00
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
This answer uses VBA, not VBScript
– Geert Bellekens
Nov 24 '18 at 6:56
1
1
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
Indeed, but I've drawn the same conclusion as you: the OP wants VBA. :) Otherwise he will tell us...
– Pragmateek
Nov 24 '18 at 15:12
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
I want VBA . Thanks for your valuable support
– user2986042
Nov 26 '18 at 7:49
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@Pragmateek Getting "type mismatch error" in line subjectMarks(j - 1) = IIf(data(i + 1, j + 1) <> "-", data(i + 1, j + 1), 999) while running the script
– user2986042
Nov 26 '18 at 8:22
@user2986042 You probably have a wrong value in your data range, i.e. which is neither
- or an integer.– Pragmateek
Nov 26 '18 at 10:00
@user2986042 You probably have a wrong value in your data range, i.e. which is neither
- or an integer.– Pragmateek
Nov 26 '18 at 10:00
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450932%2fhow-to-sort-rows-in-a-excel-sheet-and-print-to-a-file-using-vb-script%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
3
Do you want VBScript or VBA? They are not the same thing
– cybernetic.nomad
Nov 23 '18 at 17:42
VB script for excel
– user2986042
Nov 23 '18 at 19:00
Since you mention Excel Macro, and your example code is VBA I'm going to assume yo mean VBA and not VBScript. You can revert it if this is not the case.
– Geert Bellekens
Nov 24 '18 at 6:58