Calculating based on values in second sheet

GirishDhruva

Active Member
Joined
Mar 26, 2019
Messages
308
Hi Everyone,
I need some suggestions how i can solve this Using VBA

This is my workbook which i am working in
https://app.box.com/s/1rsdix4y6b7k4d9vnu3796g37b065omg
In the worksheet("main"),the highlighted column contains the formula which i have mentioned below

From above worksheets(in worksheets("main")) i need to find the round off value based on the columns
Like
>if in sheet "sal" if both columns PPL & PPLR don't have any values(that means if the value is ZERO) then the formula should be "=ROUND(D2/31*C2,0)"
>if in sheet "sal" in column PPL the values are greater than ZERO then the formula should be "=ROUND(D5/31*C5,0)+ROUND(D5/30*"The value in PPL cell",0)"
>if in sheet "sal" in column PPLR the values are greater than ZERO then the formula should be "=ROUND(D3/31*C3,0)-ROUND(D3/30*"The value in PPLR cell",0)"
>if in sheet "sal" if both columns PPL & PPLR has value greater than ZERO means then the formula should be "=ROUND(D4/31*C4,0)+ROUND(D4/30*"The value in PPL cell",0)-ROUND(D4/30*"The value in PPLR cell",0)"

Below is the code which i tried
Code:
Option Explicit

Sub LATAA()
Dim Nxt As Long, Hdr As String
    Nxt = Cells(2, Columns.Count).End(xlToLeft).Offset(, 1).Column
    Hdr = Range(Cells(1, 1), Cells(1, Nxt - 1)).Address(, , xlR1C1)
    Range(Cells(2, Nxt), Cells(Rows.Count, Nxt - 1).End(xlUp).Offset(, 1)).FormulaR1C1 = _
        "=SUMPRODUCT(((" & Hdr & "=""BS"")/31)*(" & Hdr & "=""ATT""),(rc1:rc[-1]))"
End Sub
BUT I know we cant use * in SUMPRODUCT and can you suggest me with other one

Note: The formula should also be visible in main sheet

Regards
Dhruv
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

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