I am a novice. I need this urgently in order to help the records of a ‘Welfare Group’ I belong to where Weekly Voluntary Contributions are made.
I want help on how a “Loop” in this code below could help me enter inputs in the cells C2, D2, E2, and F2 immediately the cell A2 is clicked or triggered (The VBA code given below is able to this).
Now, the cells, C3, D3, E3, and F3 should also take up data immediately cell A3 is clicked. This should be the same for C4, D4, E4, and F4 when A4 is clicked. This should continue. This should be the sequence for inputting data in the cells within the range C2:F5
(The total from C2, D2, E2, and F2 should not exceed the value in B2)
I also wish, if possible, the dates captured in cells C2, D2, E2, and F2 be displayed on the “Inputbox” respectively in order to be cautious of the date an amount is keyed.
Refer to sample table below;
A B C D E F
1 |Name of Member| Total Cont.|5th Nov. 23| 12th Nov. 23 |19th Nov. 23| 26th Nov. 23|
2 | Daniel Harry | 300.00 | 100.00 | 50.00 | 29.00 | 121.00 |
3 | Adams Hey | | | | | |
4 | Ayoti Kabri | | | | | |
5 | Adams Ford | | | | | |
Hope you understand what I am traying to achieve.
However, this is the code I have been working around but I am stacked.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
On Error GoTo ClearError
Const iAddress As String = "A2:A5" 'Loopfor cells A3 to A5
Const mrgAddress As String = "C2,D2,E2,F2" 'Keep merged cell range unchanged
Dim iCell As Range
Set iCell = Intersect(Range(iAddress), Target)
If iCell Is Nothing Then Exit Sub
Dim mrg As Range: Set mrg = Range(mrgAddress)
Application.EnableEvents = False
Dim varEintrag As Variant
For Each iCell In mrg.Cells
varEintrag = Application.InputBox( _
Prompt:="Enter Amount to '" & iCell.Address(0, 0) _
& "' then press Enter:", _
Title:="AMOUNT TO PAY FOR THIS WEEK", _
Default:=iCell.value)
If varEintrag <> "Falsch" And varEintrag <> "False" Then
If IsNumeric(varEintrag) Then
iCell.value = CDbl(varEintrag)
Else
iCell.value = varEintrag
End If
Else
Exit For ' Cancel
End If
Next iCell
SafeExit:
If Not Application.EnableEvents Then Application.EnableEvents = True
Exit Sub
ClearError:
Debug.Print "Run-time error '" & Err.Number & "': " & Err.Description
Resume SafeExit
End Sub```
Please help me. please.
Solomom tettey Adamson is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.