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
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
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
Note: The formula should also be visible in main sheet
Regards
Dhruv