VBA look for match between cell and column then in row add amount to specific cell else copy data in new row

kaasplank

New Member
Joined
Jun 3, 2020
Messages
10
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hey all, I am looking for help on a macro. What i want to do:
see if value in B3 matches any value in column d. If it does than add one to specific cell in that row if not copy data in new row.
This is what i have now:
I figures strcomp doesn't work with ranges so tried entering the ranges as strings but this is not working either… Any ideas? (maybe with match or lookup or something else completely?)

Private Sub CommandButton1_Click()
Dim lastrow As Long, Lresult As Integer
With Lresult = StrComp(Range("B3").Text, Range("D2:D65536").Text, vbTextCompare)
If Lresult = 0 Then
lastrow = Range("D65536").End(xlUp).Row
Cells(lastrow, 8).Value = Cells(lastrow, 8) + 1
Else
Range("B3:B6").Copy
lastrow = Range("D65536").End(xlUp).Row
Sheets("Blad1").Activate
Cells(lastrow + 1, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
Cells(lastrow + 1, 8).Value = 1
End If
End With

Application.CutCopyMode = False

End Sub

Thanks in advance!
 
Thanks a lot! This is working! Just need to transpose so it fills the data from d to g instead of only under d, but i can figure that out i think! Again thanks for the help. :)
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Just one weird little think for IN0012 it is pasting down on the bottom row. Does this happen with you too?
 
Upvote 0

Forum statistics

Threads
1,215,757
Messages
6,126,693
Members
449,331
Latest member
smckenzie2016

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