Greetings,
With the help of various helpful people on the internet, I have a code running to calculate outputs of a large ammount of data automatically. However, I need to expand upon it to improve the accuracy of my calculations. This is what it does:
This is the code I have now, fully working:
This works as intended. However, I need to add another variable before the actual calculations start. I am already aware why it does not work, a Worksheet_Change does not support multiple 'targets' as I have input it below. Yet, after many tries on Google, I have found somewhat similair questions but I simply do not understand how to apply them to my situation. This is what needs to happen, with the 'new' part of it in bold:
The code, with my last attempt at getting it to work, and to get the idea of what I am trying to achieve but it will not work as it is wrong, but I do not know how to fix this:
Further information: I am running Excel 2016 in English.
I do hope I was able to make myself clear, if not my apologies.
Thanks in advance.
With the help of various helpful people on the internet, I have a code running to calculate outputs of a large ammount of data automatically. However, I need to expand upon it to improve the accuracy of my calculations. This is what it does:
- Look up if there is a value entered into column M, starting from row 26 untill the last row of the data.
- Print this value into two seperate calculation sheets ('calc' and 'calcb') on cell C7 of each calculation sheet.
- Calculations are then done and two outputs per calculation sheet will result from this, which will then be printed back on the sheet, untill there are no more values for the discharge table used to print on the calculation sheets.
This is the code I have now, fully working:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rij As Integer
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "M").End(xlUp).Row
' Only change if cells have been changed
If Not (Intersect(Target, Sheets!QH.Range("M26:M" & LastRow)) Is Nothing) Then
'Fills in input for each value
For Each Target In Worksheets("QH").Range("M26:M" & LastRow).Cells
Sheets!calc.[C7] = Target.Value
Sheets!calcb.[C7] = Target.Value
'Print values from calc sheet
Target.Offset(rij, 1) = Sheets!calc.[C36]
Target.Offset(rij, 2) = Sheets!calc.[U10]
Target.Offset(rij, 9) = Sheets!calcb.[C36]
Target.Offset(rij, 10) = Sheets!calcb.[U15]
Next Target
End If
End Sub
This works as intended. However, I need to add another variable before the actual calculations start. I am already aware why it does not work, a Worksheet_Change does not support multiple 'targets' as I have input it below. Yet, after many tries on Google, I have found somewhat similair questions but I simply do not understand how to apply them to my situation. This is what needs to happen, with the 'new' part of it in bold:
- Look up if there is a value entered into column M (containing discharge data), starting from row 26 untill the last row of the data.
- Print this value into two seperate calculation sheets ('calc' and 'calcb') on cell C7 of each calculation sheet.
- Look up if there is a value entered into column H (containing head data), starting from row 26 untill the last row of the data.
- Print this value into two seperate calculation sheets ('calc' and 'calcb') on cells C9 and C20 of each calculation sheet.
- Calculations are then done and two outputs per calculation sheet will result from this, which will then be printed back on the sheet, untill there are no more values for the discharge and head tables used to print on the calculation sheets.
The code, with my last attempt at getting it to work, and to get the idea of what I am trying to achieve but it will not work as it is wrong, but I do not know how to fix this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rij As Integer
Dim LastRow As Long
LastRow = ActiveSheet.Cells(Rows.Count, "M").End(xlUp).Row
' Only change if cells have been changed
If Not (Intersect(Target, Sheets!QH.Range("M26:M" & LastRow)) Is Nothing) Then
'Fills in input for each value
For Each Target In Worksheets("QH").Range("M26:M" & LastRow).Cells
Sheets!calc.[C7] = Target.Value
Sheets!calcb.[C7] = Target.Value
[B]
For Each Target In Worksheets("QH").Range("H26:H" & LastRow).Cells
Sheets!calc.[C9] = Target.Value
Sheets!calc.[C20] = Target.Value
Sheets!calcb.[C9] = Target.Value
Sheets!calc.[C20] = Target.Value[/B]
'Print values from calc sheet
Target.Offset(rij, 1) = Sheets!calc.[C36]
Target.Offset(rij, 2) = Sheets!calc.[U10]
Target.Offset(rij, 9) = Sheets!calcb.[C36]
Target.Offset(rij, 10) = Sheets!calcb.[U15]
Next Target
End If
End Sub
Further information: I am running Excel 2016 in English.
I do hope I was able to make myself clear, if not my apologies.
Thanks in advance.