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!
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!