VBA to use a weighting and rescaling table against information in a separate sheet

Argh_Work

New Member
Joined
Oct 17, 2023
Messages
11
Office Version
  1. 2013
Platform
  1. Windows
Hi All, desperate for help.

I have a scenario that I'd really appreciate a piece of VBA code to run.

I have a table of information in sheet 1. It runs across the rows.
Based on the data in the Score column (Column B) and the Age in the Age column (Column C). I would like the code to select the corresponding row from the Table in sheet 2 and process the information.
For example 1 the score is 1 and the age is 20 therefore the correct row would be 3 in sheet 2
Example 2 the score is 3 and the age is 72 therefore the correct row would be 10 in sheet 2
Example 3 the score is 5 and the age is 29 therefor the correct row would be 21 n sheet 2

Table Sheet 1
1715822998456.png
I

Table Sheet 2
1715823691609.png

The Information then needs to be weighted and rescaled
Examples below for the rescaling and weighting based on the table in sheet 2,
Taking the data from sheet one and multiplying it by the weighting sheet 2 and then multiplying it by the rescaling amount

1715823851423.png

After the process is run it would be amazing if the results could be displayed in a third sheet in the below format
1715824000059.png


This is well beyond my abilities but I would love a VBA code I could run as it is a becoming a really large data set that I am working with in sheet 1.

Thanks so much for your assistance,
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Here's one approach, using VBA to populate Excel formulae:

VBA Code:
Sub Test()

    Dim N As Long, StartRow1 As Long, StartRow3 As Long
    Dim score As String, wts As String, scl As String, s As String
  
    StartRow1 = 2
    StartRow3 = 2
    N = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row - StartRow1 + 1
    score = "Sheet2!B$2:B$22"
    wts = "Sheet2!D$2:P$22"
    scl = "Sheet2!Q$2:Q$22"
    s = "Match(Sheet1!B" & StartRow1 & "," & score & ",)+Match(Sheet1!C" & StartRow1 & ",{0,18,65})-1"
  
    On Error Resume Next
    Range("MyResults").ClearContents
    On Error GoTo 0
  
    With Worksheets("Sheet3").Range("A" & StartRow3).Resize(N, 3)
        .Columns(1).Formula = "=Sheet1!A" & StartRow1
        .Columns(2).Formula = "=Sheet1!C" & StartRow1
        .Columns(3).Formula = "=Sumproduct(Sheet1!D" & StartRow1 & ":P" & StartRow1 & ",Index(" & wts & "," & s & ",))*Index(" & scl & "," & s & ")"
        .Value = .Value 'optional to convert formulae to values
        .Name = "MyResults"
    End With
  
End Sub

ABCDEFGHIJKLMNOP
1IDScoreAgeW1W2W3W4W5W6W7W8W9W10W11W12W13
2Example 11200400004341000
3Example 23721111111111210
4Example 35290100301210000
Sheet1

ABCDEFGHIJKLMNOPQ
1ScoreAgeW1W2W3W4W5W6W7W8W9W10W11W12W13Scale
210
31180.10.10.12.50.89.40.10.10.11.20.20.40.00.7947
4165
520
6218
7265
830
9318
103650.10.10.12.30.14.90.10.10.14.10.20.30.00.9600
1140
12418
13465
1470
15718
16765
1790
18918
19965
2050
215180.00.00.00.00.00.00.00.00.00.00.00.00.00.0000
22565
Sheet2

ABC
1IDAgeWeighted score
2Example 1202.15
3Example 27212.19
4Example 3290.00
Sheet3
Cell Formulas
RangeFormula
A2:A4A2=Sheet1!A2
B2:B4B2=Sheet1!C2
C2:C4C2=SUMPRODUCT(Sheet1!D2:P2,INDEX(Sheet2!D$2:P$22,MATCH(Sheet1!B2,Sheet2!B$2:B$22,)+MATCH(Sheet1!C2,{0,18,65})-1,))*INDEX(Sheet2!Q$2:Q$22,MATCH(Sheet1!B2,Sheet2!B$2:B$22,)+MATCH(Sheet1!C2,{0,18,65})-1)
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,141
Members
453,021
Latest member
Justyna P

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