copy to last row from textbox on form to column if it's not duplicate item

Abdo

Board Regular
Joined
May 16, 2022
Messages
243
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello
this code will replace the whole items in column B with textbox1, but what I want copy to the bottom after last row contains item every time try copy to column B .
VBA Code:
Private Sub CommandButton1_Click()
Dim Rng As Range
Set Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
    If Application.CountIf(Rng, Trim(TextBox1.Value)) > 0 Then
        MsgBox "Match found in " & TextBox1.Name
        Else
        Rng = TextBox1
    End If
End Sub
how can I fix it, please?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hello
this code will replace the whole items in column B with textbox1, but what I want copy to the bottom after last row contains item every time try copy to column B .
VBA Code:
Private Sub CommandButton1_Click()
Dim Rng As Range
Set Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
    If Application.CountIf(Rng, Trim(TextBox1.Value)) > 0 Then
        MsgBox "Match found in " & TextBox1.Name
        Else
        Rng = TextBox1
    End If
End Sub
how can I fix it, please?
This will write the contents of the textbox to the next empty cell in column B.

VBA Code:
Private Sub CommandButton1_Click()
Dim Rng As Range

  Set Rng = Range(Range("B2"), Range("B" & Rows.Count).End(xlUp))
    
  If Application.CountIf(Rng, Trim(TextBox1.Value)) > 0 Then
    MsgBox "Match found in " & TextBox1.Name
  Else
    Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = TextBox1
  End If

End Sub
 
Upvote 0
thanks
but shouldn't copy duplicate item!
 
Upvote 0
based on original code will prevent adding duplicate item regardless contains small or big letters for the same item also contains spaces. so there is no limitation after how many times should be duplicates
 
Upvote 0

Forum statistics

Threads
1,225,476
Messages
6,185,205
Members
453,283
Latest member
Shortm88

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