hell
i have this code and i try updating data to sheet2 from sheet1 by choose the name if the data of name is already existed should update in sheet2 if not then copy a new data to bottom
HTML Code:
hell
i have this code and i try updating data to sheet2 from sheet1 by choose the name if the data of name is already existed should update in sheet2 if not then copy a new data to bottom
HTML Code:
Hi ABDELFATTA,
I am confused about what you're trying to do. What should be entered in the Inputbox ? A name or year ? If found in Sheet2, it should update all cells of the same row & if not found add a new record at the bottom ?
Last edited by ABDELFATTA; 09-18-2020 at 04:00 PM.
Try below code ...
Sub test() Dim StrName$, Rg1 As Range, Rg2 As Range StrName = InputBox("enter name") Set Rg1 = Sheets("Sheet1").Columns(2).Find(StrName, lookat:=xlWhole) If Len(StrName) = 0 Then MsgBox "Nothing was entered !", vbExclamation: Exit Sub ElseIf Rg1 Is Nothing Then MsgBox StrName & " doesn't exist in Sheet1", vbExclamation: Exit Sub End If With Sheets("Sheet2") Set Rg2 = .Columns(2).Find(StrName, lookat:=xlWhole) If Not Rg2 Is Nothing Then Rg2.Resize(, 4) = Rg1.Resize(, 4).Value Else .Cells(Rows.Count, 2).End(xlUp).Offset(1).Resize(, 4) = Rg1.Resize(, 4).Value .Cells(Rows.Count, 1).End(xlUp).Offset(1) = .Cells(Rows.Count, 1).End(xlUp).Value + 1 End If End With End Sub
If I was able to help, you can thank me by clicking the * Add Reputation under my user name
thanks nank the code works as what i want but if is possible i would to be letters of name are sensitive so , how i can use function lcase and ucase?
In order for the search to be case sensitive, add the below to the above code red syntax
Sub test() Dim StrName$, Rg1 As Range, Rg2 As Range StrName = InputBox("enter name") Set Rg1 = Sheets("Sheet1").Columns(2).Find(StrName, lookat:=xlWhole, MatchCase:=True) If Len(StrName) = 0 Then MsgBox "Nothing was entered !", vbExclamation: Exit Sub ElseIf Rg1 Is Nothing Then MsgBox StrName & " doesn't exist in Sheet1", vbExclamation: Exit Sub End If With Sheets("Sheet2") Set Rg2 = .Columns(2).Find(StrName, lookat:=xlWhole, MatchCase:=True) If Not Rg2 Is Nothing Then Rg2.Resize(, 4) = Rg1.Resize(, 4).Value Else .Cells(Rows.Count, 2).End(xlUp).Offset(1).Resize(, 4) = Rg1.Resize(, 4).Value .Cells(Rows.Count, 1).End(xlUp).Offset(1) = .Cells(Rows.Count, 1).End(xlUp).Value + 1 End If End With End Sub
brilliant ! i would sorry about not add reputation for you indeed you've solved many thread honestly, i thought in earlier time i have ever added to you sorry about it
many thanks buddy
Glad to help & thanks for the added Rep
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks