+ Reply to Thread
Results 1 to 8 of 8

copy data from sheet to another based on name by inputbox

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    copy data from sheet to another based on name by inputbox

    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: 
    Attached Files Attached Files

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: copy data from sheet to another based on name by inputbox

    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 ?

  3. #3
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: copy data from sheet to another based on name by inputbox

    hi nankw83 it should enter the name into inputbox as for this
    Quote Originally Posted by nankw83 View Post
    Hi ABDELFATTA,

    If found in Sheet2, it should update all cells of the same row ?
    yes i would this but forget copy to the bottom if name is not existed should show message not data found
    Last edited by ABDELFATTA; 09-18-2020 at 04:00 PM.

  4. #4
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: copy data from sheet to another based on name by inputbox

    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

  5. #5
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: copy data from sheet to another based on name by inputbox

    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?

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: copy data from sheet to another based on name by inputbox

    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

  7. #7
    Forum Contributor
    Join Date
    06-02-2019
    Location
    libya
    MS-Off Ver
    2010
    Posts
    734

    Re: copy data from sheet to another based on name by inputbox

    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

  8. #8
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: copy data from sheet to another based on name by inputbox

    Glad to help & thanks for the added Rep

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Copy a template sheet to end of workbook using a InputBox to rename
    By NZ_Shane in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-12-2016, 10:09 AM
  2. [SOLVED] VBA- Using inputbox to filter and copy data
    By Heisenberg_2 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 05-07-2016, 02:56 AM
  3. Replies: 2
    Last Post: 01-23-2016, 01:16 PM
  4. Sheet reference based on inputbox value
    By ben10 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-16-2013, 11:28 PM
  5. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM
  6. [SOLVED] Macro to Copy Data from one Sheet A to Sheet B based on value in cell on sheet A
    By scass in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-11-2012, 07:21 PM
  7. [SOLVED] Copy sheet based on Inputbox - data to be copied variable.
    By nickmax1 in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 09-07-2012, 10:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1