auto sum

Trevor3007

Well-known Member
Joined
Jan 26, 2017
Messages
667
Office Version
  1. 365
Platform
  1. Windows
Hi,

I dont even know if my request is possible? But here goes. The screenshot below , a customer has this spreadsheet which he gets exported from his companies payroll. As it differs from month to month he cannot just place the apllicable =sum() in the same row as last ime as the value in cols d & e will change.

So, rather than doa nested =if, is there it possible to have VB do it?

Col 'I' would display the total using the rate displayed in col 'd' x the hours in col 'E' x £8.30.

many thanks & good luck.

1660074598987.png
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hi,

What differs from month to month?

Thanks
 
Upvote 0
is there it possible to have VB do it?
Is this what you mean?
Test with a copy of your workbook.

VBA Code:
Sub EnterCalculation()
  With Range("I2:I" & Range("D" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=RIGHT(SUBSTITUTE(RC[-5],"" "",REPT("" "",20)),20)*RC[-4]"
    .Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & .Address & ")"
  End With
End Sub
 
Upvote 0
Is this what you mean?
Test with a copy of your workbook.

VBA Code:
Sub EnterCalculation()
  With Range("I2:I" & Range("D" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=RIGHT(SUBSTITUTE(RC[-5],"" "",REPT("" "",20)),20)*RC[-4]"
    .Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & .Address & ")"
  End With
End Sub
works great, but ( my fault) where it states TES Sun Core 1, this would mean e x 1.5

hope you can sort ..thank you.
 
Upvote 0
where it states TES Sun Core 1, this would mean e x 1.5
Is that the only possible anomaly?

Try
VBA Code:
Sub EnterCalculation_v2()
  With Range("I2:I" & Range("D" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=IF(RC[-5]=""TES Sun Core 1"",1.5,RIGHT(SUBSTITUTE(RC[-5],"" "",REPT("" "",20)),20))*RC[-4]"
    .Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & .Address & ")"
  End With
End Sub
 
Upvote 0
Is this what you mean?
Test with a copy of your workbook.

VBA Code:
Sub EnterCalculation()
  With Range("I2:I" & Range("D" & Rows.Count).End(xlUp).Row)
    .FormulaR1C1 = "=RIGHT(SUBSTITUTE(RC[-5],"" "",REPT("" "",20)),20)*RC[-4]"
    .Offset(.Rows.Count).Resize(1).Formula = "=SUM(" & .Address & ")"
  End With
End Sub

Hi Peter_SSs
thank you so much for your help. The only abdominally I can see is the total hours in Col I, which needs to be x £8.90 into col j and a total of all ( see screenshot below).





1660197631413.png



Once I again thank you. I could not of even gotten close to this with out your skills.
 
Upvote 0
Sorry, I missed the extra multiplication. Can you confirm that the extra multiplication is 8.90 as you said in post 6 or 8.30 as you said in post 1?

Also, it would help greatly if in future you could provide any sample data and expected results with XL2BB so that we can easily copy to test with rather than manually typing out the data (with likely mistakes for my typing ;))
 
Upvote 0
Can you confirm that the extra multiplication is 8.90 as you said in post 6 or 8.30 as you said in post 1?
Here I have used 8.90 but you can easily see where to change it if required.

Rich (BB code):
Sub EnterCalculation_v3()
  With Range("I2:J" & Range("D" & Rows.Count).End(xlUp).Row)
    .Formula = Array("=IF(D2=""TES Sun Core 1"",1.5,RIGHT(SUBSTITUTE(D2,"" "",REPT("" "",20)),20))*E2", "=I2*8.9")
    .Offset(.Rows.Count).Resize(1).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
  End With
End Sub
 
Upvote 0
Solution
Here I have used 8.90 but you can easily see where to change it if required.

Rich (BB code):
Sub EnterCalculation_v3()
  With Range("I2:J" & Range("D" & Rows.Count).End(xlUp).Row)
    .Formula = Array("=IF(D2=""TES Sun Core 1"",1.5,RIGHT(SUBSTITUTE(D2,"" "",REPT("" "",20)),20))*E2", "=I2*8.9")
    .Offset(.Rows.Count).Resize(1).FormulaR1C1 = "=SUM(R2C:R[-1]C)"
  End With
End Sub
that will do nicley Sir!!

yes orginally , but i can change that and or show the gut how to. Could 8.90, be calculated using a cell ref rather then within the code, as it will be easier for the guy ( and I am sure others will use) . perhaps promted a message box asking to rate to be inserted or not but still looking to that particual cell IE m2?

thanks again...fantastic
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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