I am trying to paste grades in excel sheet based on marks
i do this but this shows only F in excel sheet .. i want if anybody has marks >=80 then want to show A grade .. and if anybody hay >=70 then B
and if anybody have less than 70 then want to show F
UPDATED CODE
clc,clear all
filename = 'PROJECT..xlsx';
table = readtable(filename);
data = xlsread(filename);
[r,c] = size(data);
total_courses = c;
table.SumofMarks = zeros(r,1);
table.Percentage = zeros(r,1);
table.StudentGrade = repmat({''},r,1);
% Sum of marks in different courses and their percentage.
format bank
Sum_of_Marks = sum(data,2);
Student_Percentage = Sum_of_Marks./total_courses;
T = horzcat(Sum_of_Marks,Student_Percentage);
N = length(Student_Percentage);
table.SumofMarks = Sum_of_Marks;
table.Percentage = Student_Percentage;
for i = 1:63
sheet1=readtable(filename);
mark=sheet1{i,{'CALCULUS','DISCRETE','ECONOMICS','ISLAMIAT','STATISTICS'}};
if mark(mark<40)
grade='F';
sheet1(i,'StudentGrade')=cellstr(grade);
else
continue
end
end
writetable(table,filename)
xlswrite(filename,T,1, 'H2')
xlswrite(filename,grade,1,'J2')
these are the errors which I get
Error using getRowIndices (line 75)
Row index exceeds table dimensions.
Error in table/subsrefBraces (line 17)
[rowIndices,numRowIndices] =
getRowIndices(t, s(1).subs{1});
Error in table/subsref (line 60)
[varargout{1:nargout}] =
subsrefBraces(t,s);
Error in lab4 (line 38)
mark=sheet1{i,{'CALCULUS','DISCRETE','ECONOMICS','ISLAMIAT','STATISTICS'}};
i tried this but this code doesnt work
how i do this
i paste link where my file is located.. and I want if any student get less than 40 marks in any subject then want to show F grade.. this code shows if total marks is less than 40 .. where as I want to show if marks is less than 40 in any subject
this is the excel file
https://drive.google.com/file/d/1VQ8XxAQPu6reY0SCNV9Rxt65w1koduGA/view?usp=sharing
I don't have Excel installed, so I can't check the part about reading and writing to Excel, but you should replace
if R>=80
table.StudentGrade{i} = 'A';
elseif R>=70
table.StudentGrade{i} = 'B';
elseif R <70
table.StudentGrade{i}= 'F';
end
with
if R(i)>=80
table.StudentGrade{i} = 'A';
elseif R(i)>=70
table.StudentGrade{i} = 'B';
elseif R(i) <70
table.StudentGrade{i}= 'F';
end
Related
Help me I need to create a Userform for my personal calculations. But I ran into a lot of problems. Because I've never written a program before.
When I enter a value 0 or enter a value other than 0 and delete it in the text field PriceCoinBuy, BuyCoin , PriceCoinSell , SellCoin , Vat one of the fields I will get Msg : Run-time error '6'; overflow.
But when I put a number other than 0 in the BuyCoin field, I get Msg : Run-time error '11'; Division by zero.
I've been searching for a solution for 2 days but can't find it in please help.
I have 5 textboxes for input.
Sub SumAll()
Dim A, B, C, D, E, F, G, H, I, J, K, V As Double
A = Val(Order.PriceCoinBuy.Value)
B = Val(Order.BuyCoin.Value)
C = Val(Order.PriceCoinSell.Value)
D = Val(Order.SellCoin.Value)
V = Val(Order.Vat.Value)
'-------------- Math --------------
E = CDbl(B) / A
F = CDbl(E) * (V / 100)
G = CDbl(E) - F
H = CDbl(G) * A
I = CDbl(D) * C
J = CDbl(I) * (V / 100)
K = CDbl(I) - J
'---------------- Show -------------
Order.GetCoin.Text = Format(E, "##,##0.000000")
Order.AfterVatBuy.Text = Format(F, "##,##0.0000")
Order.CoinBalance.Text = Format(G, "##,##0.000000")
Order.ToMoney.Text = Format(H, "##,##0.00")
Order.GetMoney.Text = Format(I, "##,##0.00")
Order.AfterVatSell.Text = Format(J, "##,##0.00")
Order.MoneyBalance.Text = Format(K, "##,##0.00")
End Sub
So I created a scripting to retrieve data from SAP Gridview object to an Excel sheet. Some columns I needed to replace some characters because this data is consumed by a Power Bi report. For example:
4,350.00 will be replaced for the value 4350. So I do two replaces, the first removing the . and the second replacing the , with .
The problem is that the replace is being applied in every data retrieved. Here's the code.
For i = 0 To GridView.RowCount - 1
For j = 0 To GridView.ColumnCount - 1
shtInput.Cells(z + i, j + 1) = GridView.GetCellValue(i, GridView.ColumnOrder(j))
If j > 8 And j < 19 Then:
rep = GridView.GetCellValue(i, GridView.ColumnOrder(j))
rep = replace(rep, ".", "")
rep = replace(rep, ",", ".")
shtInput.Cells(z + i, j + 1) = rep
Next j
shtInput.Cells(z + i, Area) = "Finance"
If i Mod 32 = 0 Then
GridView.SetCurrentCell i, CStr(Columns(0))
GridView.firstVisibleRow = i
End If
Next i
There's a data column that the script capture the value 21.02.2021 and replace it with 21,02,2021.
I have to import an Excel file into an Access db. My Excel has a column called 'Description'. Usually the description is long a cell, but it can happens that is more long. If it is long more than 255 characters, I cut the string and I modify last 3 characters with '...'.
When I run the program, though, I have an error "Index and length must refer to a location within the string".
I tried even to erase the check on the length, but obviously I had this error "Field is too small to accept the amount of data you attempted to add"
If flag = 2 Then
stringVoice = grid(r, 3).Text
voc.Description = voc.Description & stringVoice
If voc.Description.Length > 255 Then
voc.Description = grid(r, 3).Text.ToString.Substring(0, 252) + "..."
End If
End If
This is the code that produced the Index and length error. Same check has done before if inside a single cell there are more than 255 characters
Case 1 'voce
id = id + 1
flag = 2
voc = New cVoce
c_Voc = voc.Cod_Chapter
p_Voc = voc.Cod_Paragraph
voc.Cod_Chapter = grid(r, 1).Text.Substring(0, 1)
voc.Cod_Paragraph = grid(r, 1).Text.Split(".")(0)
voc.Cod_Voice = Right(vett(0), 2)
If grid(r, 3).Text.Length > 255 Then
voc.Description = grid(r, 3).Text.ToString.Substring(0, 252) + "..."
Else
voc.Description = grid(r, 3).Text.ToString
If voc.Description.EndsWith("-") Then
a = Replace(voc.Description, "-", "")
voc.Description = a
End If
End If
stringVoice = voc.Description
voices.Add(voc)
but in this case I've never had an error.
Can anyone help me to fix my code?
As part of a larger script, I am trying to replace fraction values with decimal values in excel using vbscript. I can always count on the values to have a specific column and a specific format.
Excel example expected input column B:
51-7/16
1-1/2
2
15-7/8
Excel example desired output column B:
51.4375
1.5
2
15.875
I know it will always be to a 1/16th. So my idea was to go through the list looking for each possible fraction, find a cell that contains that fraction, and replace it with the corresponding decimal.
Questions: How do I tell the script to find a cell that contains a value and how do I replace that fraction with the decimal?
closest example Search and Replace a number of characters in Excel using VBscript
Attempt:
Dim FMember (14)
FMember(0) = "-1/16"
FMember(1) = "-1/8"
FMember(2) = "-3/16"
FMember(3) = "-1/4"
FMember(4) = "-5/16"
FMember(5) = "-3/8"
FMember(6) = "-7/16"
FMember(7) = "-1/2"
FMember(8) = "-9/16"
FMember(9) = "-5/8"
FMember(10) = "-11/16"
FMember(11) = "-3/4"
FMember(12) = "-13/16"
FMember(13) = "-7/8"
FMember(14) = "-15/16"
Dim DMember(14)
DMember(0) = ".0625"
DMember(1) = ".125"
DMember(2) = ".1875"
DMember(3) = ".25"
DMember(4) = ".3125"
DMember(5) = ".375"
DMember(6) = ".4375"
DMember(7) = ".5"
DMember(8) = ".5625"
DMember(9) = ".625"
DMember(10) = ".6875"
DMember(11) = ".75"
DMember(12) = ".8125"
DMember(13) = ".875"
DMember(14) = ".9375"
Dim endRow2
endRow2 = objSheet2.UsedRange.Rows.Count
For lngPosition = LBound(FMember) To UBound(FMember)
For r = 1 To endRow2
If objSheet2.Cells(r, objSheet2.Columns("B").Column).Value = FMember(lngPosition) Then
objSheet2.replace
End If
Next
Next
Use split()
Function fract(str As String) As Double
Dim strArr() As String
If InStr(str, "-") Then
strArr = Split(str, "-")
fract = strArr(0) + Application.Evaluate(strArr(1))
Else
fract = Application.Evaluate(str)
End If
End Function
Then you can use it as a worksheet function:
=fract(A1)
According to this topic:
How to convert a column number (e.g. 127) into an excel column (e.g. AA)
I don't understand what is in algorithm:
here
Could someone explain me, what is happening in a while loop?
It is, in effect, "converting" the column number to base 26, where the "digits" are the letters A..Z.
For example, for column 720:
modulo = (720-1)%26 = 17
columnName = 'R'
dividend = (720-17)/26 = 27
modulo = (27-1)%26 = 0
columnName = A+columnName = AR
dividend = (27-0)/26 = 1
modulo = (1-1)%26 = 0
columnName = A + columnName = AAR
dividend = (1-0)/26 = 0
Resulting in AAR.