I have the following range of cells B2:Y3700. I want that when a value from 1 to 9999 is inserted in one cell of the above mentioned range, to copy the row number of that cell in the cell that is located in column Z and row is the number inserted in that cell. For example, if the number "1234" is inserted in one cell from range B2:Y3700, to enter in cell Z1234 the number of the row where is located the respective cell. At same the time is very important to me to not permit to insert the same number in B2:Y3700, so i believe that is need a macro code to check the cell from column z to see if value already exist . Sorry for me english, Thanks.
Send Row Number Of Changed Cell To Cell Where Row Resides In Cell
-
-
-
Re: Send Value To Specific Cell
Providing you are only using figures:
CodePrivate Sub Worksheet_Change(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Not Intersect(Target, Range("C1:G20")) Is Nothing Then 'change to suit Range("A" & Target.Value).Value = Target.Row 'change to suit End If End Sub
the above code goes in the worksheet code module you are working with (Alt+F11, then double click the sheet name on your left and paste this in!
-
Re: Send Value To Specific Cell
Thanks for your reply Simon Lloyd. I try your code in a new Worksheet and i insert random values to see if is working, but after many try's i don't know what this code does. I need a code that if a number is inserted in a cell from a specified range to send the number of the row in a cell that is located in column Z (or any letter) and the row is the number inserted in that cell. It is very important to not permit entering of a number that have been already inserted in that range. The attached file has no formulas or macro code, it is manual completed for detailing my needs.
--------
Regards,
Marius -
Re: Send Value To Specific Cell
Marius, i haven't looked at your attachment, as per your first request you said that if you enter a number in any cell within a specific range (in my example the range was C1:G20) then the row number of that cell should be entered into the cell number of the entry and that should appear in column Z (in my example A).
So, in my example if you enter 5 in lets say C2 then A5 will display 2 (meaning row 2), this is what i took your request to mean!
Can you clarify?
-
Re: Send Value To Specific Cell
Sorry Simon for my reply post, i paste the code in "ThisWorkbook", not in Sheet. The code work very good, but i need that after i delete or edit a value from C1:G20, the column A must be corrected. This way i will avoid the error "Run time-error 1004: method 'range' of object '_Worksheet' failed " .To denied duplicate values i modify the code :
Code
Display MorePrivate Sub Worksheet_Change(ByVal Target As Range) If Target.Count > 1 Then Exit Sub If Not Intersect(Target, Range("C1:G20")) Is Nothing Then If Range("A" & Target.Value).Value > 0 Then MsgBox "Code already exist" Target.Value = "" Else Range("A" & Target.Value).Value = Target.Row End If End If End Sub
-
-
Re: Send Row Number Of Changed Cell To Cell Where Row Resides In Cell
One more time i need help. My final macro code is
Code
Display MorePrivate OldValue As Variant Private Sub Worksheet_SelectionChange(ByVal Target As Range) OldValue = Target.Value End Sub Private Sub Worksheet_Change(ByVal Target As Excel.Range) If Target.Count > 1 Then Exit Sub On Error Resume Next If Not Intersect(Target, Range("B1:AT3700")) Is Nothing Then Range("CX" & OldValue).Value = "" End If If Not Intersect(Target, Range("B1:AT3700")) Is Nothing Then If Range("CX" & Target.Value).Value < 1 Then If Not Intersect(Target, Range("B1:AT3700")) Is Nothing Then Range("CX" & Target.Value).Value = Target.Row End If Else Target.Value = "Cod Existent" End If End If End Sub
My new code resolve the previous problem, with the edit or delete value from cell, but when i select multiple cells and press delete key to clear values from them, or i drag with mouse the value from a cell to other cells the macro code is skipped. Is possible to make the macro code to run like a formula in excel, or to not permit editing or deleting of more than one cell.
--------------
Regards,
Marius
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!