Need VBA code Help

4 Barrel Harold

New Member
Joined
Jun 15, 2018
Messages
21
I'm not very good with vba's so I hope i explain this right. Ok I need to enter a value in cell E6, after value is entered and when the button is pressed the vba searches for same value in column C (which answer to search would be C11). then I need the vba to add the input data in E6 to E11 (20+40 =60). After the addition is done then the vba would clear contents in Cell E6. E6 would be waiting on next value and button pressed again
 

Attachments

  • VBA Problem.png
    VBA Problem.png
    30 KB · Views: 8

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
try using below code

VBA Code:
lr = Sheets("sheet4").Range("d8").SpecialCells(xlCellTypeLastCell).Row
For j = 8 To lr
    If Cells(j, 4) = Range("e6") Then
        Range("e2").Value = Range("e6").Value + Cells(j, 5).Value
    Else
    End If
Next j
Range("e6").Value = ""
 
Upvote 0
Another option
VBA Code:
Sub fourBarrelHarold()
   Dim Fnd As Range
   Set Fnd = Range("C:C").Find(Range("E6").Value, , , xlWhole, , , , , False)
   If Not Fnd Is Nothing Then
      Fnd.Offset(, 2).Value = Fnd.Offset(, 2).Value + Range("E6").Value
   Else
      MsgBox "Not found"
   End If
End Sub
 
Upvote 0
Another option
VBA Code:
Sub fourBarrelHarold()
   Dim Fnd As Range
   Set Fnd = Range("C:C").Find(Range("E6").Value, , , xlWhole, , , , , False)
   If Not Fnd Is Nothing Then
      Fnd.Offset(, 2).Value = Fnd.Offset(, 2).Value + Range("E6").Value
   Else
      MsgBox "Not found"
   End If
End Sub
Worked like a charm THANKS
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

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