Very hard Task ( Mark and Percentage)

smartguy

Well-known Member
Joined
Jul 14, 2009
Messages
778
Hello all,

I have excel file in the below format.


Excel Workbook
ABC
1Studentsubjectmark
2aben43
3abev32.95
4abed32.95
5acEV741.77
6acen57
7aced4356
8adee234
9adrad65.123
10adEN123.45
11adEV2345.67
12adev123
13adEG12.34
Sheet1


I want to get EN,EV & EG details..

Answer :


Excel Workbook
EFGH
1StudentENEVEG
2ab433.295%
3ac741.7774.177%
4ad123.45234.567%1.234%
Sheet1
 
Student subject mark Student EN EV EG
ab en 43 ab 43 3.30%
ab ev 32.95 ac 57 74.18%
ab ed 32.95 ad 123.45 234.57% 1.23%
ac EV 741.77
ac en 57
ac ed 4356
ad ee 234
ad rad 65.123
ad EN 123.45
ad EV 2345.7
ad ev 123

ad EG 12.34
you still show 2 values here
if that isnt the case a simple sumproduct will do it, why vba?
 
Upvote 0

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
smartguy,


What is your logic for Student ad, when there are 2 subject's, EV and ev?


Excel Workbook
ABCDEFGH
8adee234ad123.45234.567%1.234%
9adrad65.123
10adEN123.45
11adEV2345.67
12adev123
13adEG12.34
Sheet1
 
Upvote 0
smartguy,


Sample raw data before the macro:


Excel Workbook
ABCDEFGH
1Studentsubjectmark
2aben43
3abev32.95
4abed32.95
5acEV741.77
6acen57
7aced4356
8adee234
9adrad65.123
10adEN123.45
11adEV2345.67
12adev123
13adEG12.34
14
Sheet1





After the macro:


Excel Workbook
ABCDEFGH
1StudentsubjectmarkStudentENEVEG
2aben43ab433.295%
3abev32.95ac5774.177%
4abed32.95ad123.45234.567%1.234%
5acEV741.77
6acen57
7aced4356
8adee234
9adrad65.123
10adEN123.45
11adEV2345.67
12adev123
13adEG12.34
14
Sheet1





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.


Code:
Option Explicit
Sub ReorgData()
' hiker95, 08/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=574976
Dim I(), A(), O(), k
Dim d As Object
Dim r As Long, c As Long, f As Long, s As Long, e As Long
Set d = CreateObject("scripting.dictionary")
I = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 3))
A = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1))
For r = 1 To UBound(A)
  If Not d.exists(A(r, 1)) Then d(A(r, 1)) = d.Count
Next r
k = d.Keys
ReDim O(1 To d.Count + 1, 1 To 4)
For r = 1 To d.Count
  O(r, 1) = k(r - 1)
Next r
O(1, 2) = "EN"
O(1, 3) = "EV"
O(1, 4) = "EG"
For r = 2 To d.Count
  s = Application.Match(O(r, 1), A, 0)
  e = Application.Match(O(r, 1), A, 1)
  For c = s To e
    If LCase(I(c, 2)) = "en" Or UCase(I(c, 2)) = "EN" Then
      O(r, 2) = I(c, 3)
    ElseIf I(c, 2) = "EV" Then
      O(r, 3) = I(c, 3) / 1000
    ElseIf LCase(I(c, 2)) = "ev" And O(r, 3) = "" Then
      O(r, 3) = I(c, 3) / 1000
    ElseIf I(c, 2) = "EG" Then
      O(r, 4) = I(c, 3) / 1000
    End If
  Next c
Next r
Columns("E:H").Clear
Range("E1").Resize(UBound(O), 4) = O
Range("E1:H" & UBound(O)).HorizontalAlignment = xlCenter
Range("G2:H" & UBound(O)).NumberFormat = "0.000%"
End Sub


Then run the ReorgData macro.
 
Upvote 0
smartguy,

Thanks for the feedback.

Glad I could help.

You are very welcome.

Come back anytime.
 
Upvote 0
Thanks Once Again...

images
 
Upvote 0
Hello all,

Code:
Option Explicit
Sub ReorgData()
' hiker95, 08/28/2011
' http://www.mrexcel.com/forum/showthread.php?t=574976
Dim I(), A(), O(), k
Dim d As Object
Dim r As Long, c As Long, f As Long, s As Long, e As Long
Set d = CreateObject("scripting.dictionary")
I = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 3))
A = Range(Cells(1, 1), Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1))
For r = 1 To UBound(A)
  If Not d.exists(A(r, 1)) Then d(A(r, 1)) = d.Count
Next r
k = d.Keys
ReDim O(1 To d.Count + 1, 1 To 4)
For r = 1 To d.Count
  O(r, 1) = k(r - 1)
Next r
O(1, 2) = "EN"
O(1, 3) = "EV"
O(1, 4) = "EG"
For r = 2 To d.Count
  s = Application.Match(O(r, 1), A, 0)
  e = Application.Match(O(r, 1), A, 1)
  For c = s To e
    If LCase(I(c, 2)) = "en" Or UCase(I(c, 2)) = "EN" Then
      O(r, 2) = I(c, 3)
    ElseIf I(c, 2) = "EV" Then
      O(r, 3) = I(c, 3) / 1000
    ElseIf LCase(I(c, 2)) = "ev" And O(r, 3) = "" Then
      O(r, 3) = I(c, 3) / 1000
    ElseIf I(c, 2) = "EG" Then
      O(r, 4) = I(c, 3) / 1000
    End If
  Next c
Next r
Columns("E:H").Clear
Range("E1").Resize(UBound(O), 4) = O
Range("E1:H" & UBound(O)).HorizontalAlignment = xlCenter
Range("G2:H" & UBound(O)).NumberFormat = "0.000%"
End Sub

The above code is working fine...

But data is not there ( Column A to C) means i got Run time Error....

Type Miss match - Run time Error -13

Please help to solve the issue....
 
Upvote 0
smartguy,

Thanks for the Private Message.

But data is not there ( Column A to C) means i got Run time Error....

What does this mean?


Do you want the results to overwrite the original data in columns A, B, and C?

Or, do you want the results in a new worksheet Results?
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top