problem with autoincrement

rodanny

New Member
Joined
Apr 24, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
Hello,
sorry for my poor english....
I have the following problem

When I fill in a value in the field in column D (the next row with 24), I automatically want column A to increase my position from the row above.It works when I use the Enter key, but if after completing field D I try to go to the next field with Tab or Arrows, the confirmation is no longer done.Thank you

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 4 Then
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "D").End(xlUp).Row - 1
Dim ans As String
Dim r As Long
Dim rr As Long
Dim searchTerm As Range
ans = Target.Value
r = Target.Row
Set searchTerm = Range("D24:D" & Lastrow).Find(what:=ans, searchorder:=xlByColumns, searchdirection:=xlPrevious)
If searchTerm Is Nothing Then Exit Sub
rr = searchTerm.Row + 1
Cells(rr + 1, 1).Value = rr + 1 - 23 'incrementam randul cu 1 unitate si scadem randul 23 / numerotarea incepe de la randul 24 care e in tabel pozitia 1

End If

End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I found a not very nice solution....but it worksIf you have other simpler ideas, they are welcome.

If Target.Column = 4 Then ' 4
' If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "D").End(xlUp).Row - 1
Dim ans As String
Dim r As Long
Dim rr As Long
Dim searchTerm As Range
ans = Target.Value
r = Target.Row
If Target.Column <> ActiveCell.Column Then
' Set searchTerm = Range("D24:D" & Lastrow).Find(what:=ans, searchorder:=xlByColumns, searchdirection:=xlPrevious)
' If searchTerm Is Nothing Then Exit Sub
rr = Target.Row ' searchTerm.Row+1
' Cells(rr + 1, 1).Value = rr + 1 - 23 'incrementam randul cu 1 unitate si scadem randul 23 / numerotarea incepe de la randul 24 care e in tabel pozitia 1

Cells(rr + 1, 1).Value = rr + 1 - 23 'incrementam randul cu 1 unitate si scadem randul 23 / numerotarea incepe de la randul 24 care e in tabel pozitia 1
End If
End If
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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