+ Reply to Thread
Results 1 to 6 of 6

VBA code to search from different sheet > Copy the row > Paste on different sheet.

  1. #1
    Registered User
    Join Date
    12-02-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    4

    VBA code to search from different sheet > Copy the row > Paste on different sheet.

    Hi All,

    I am seeking your help on VBA code.

    1. Currently i had a range of data in sheet1 ( A1:G4000 )
    2. Sheet1 Col A1 are Unique alphanumeric code. ( Use to generate Barcode )
    3. Under sheet2 A1:A4000 will be input, which user will scan the barcode.
    4. Once the barcode scanned and input to range of A1:A4000, the cell will be uneditable with password protection.
    5. If the same barcode being scanned again, it will not capture in range A1:A4000. Active cell will remain at the empty cell to be ready for input again.

    Above is the function that will be in Range A1:A4000. Below is the trigger needed whenever the barcode scanned / the cell had input.

    6. Whenever the Cell Range of A1:A4000 had a input, VBA will trigger and search over the Sheet1 A1:A4000. Once the Unique code searched, copy Bx:Gx and paste into the cell which under the same room of the Barcode being scanned. And finally the entire row will be protected ( If this option is not available, is ok ).


    Appreciate that someone can enlighten me on this option with VBA. As i do not have any knowledge on VBA coding. Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA code to search from different sheet > Copy the row > Paste on different sheet.

    Hi qpywsqp,
    try this (see attachment)
    password for Sheet2 is "111" (without quotes)
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-02-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA code to search from different sheet > Copy the row > Paste on different sheet.

    Hi Nilem, thanks a lot to answer my question.

    The code is looking good, just that a few more step to final tune. Not sure below listed possible to happen or not, please advice.

    1. If sheet2 A2:A10 has data, possible to add in a code to prevent skip row? Meaning that if i key in a data in A15, it will automatically key into A11 instead?
    2. I found the code you provided are not allow to delete the data on Col Bx:Gx when Ax has a valid data. Possible to make it only Col A is allow to key in data?

    Besides that if i would like to make the range wider, am i just need to adjust the figure under? :
    " If Not r Is Nothing Then
    With Target.Resize(, 20)
    .Value = r.Resize(, 20).Value: .Locked = True"

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: VBA code to search from different sheet > Copy the row > Paste on different sheet.

    yes, Target.Resize(, 20).Value = r.Resize(, 20).Value
    try again
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    12-02-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA code to search from different sheet > Copy the row > Paste on different sheet.

    Thank Nilem.

    It looks good after revised. At the moment i did not have barcode scanner with me to really test out the file.

    Once i tried, if there is any amend need to fine tune ill reply from here. Hope you can solve my problem.

    Many many thanks for you help. Thank you.

  6. #6
    Registered User
    Join Date
    12-02-2012
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: VBA code to search from different sheet > Copy the row > Paste on different sheet.

    Hi Nilem,

    Finally i got my scanner with me to try out your code. It is working nearly perfect to what i am looking at. Perhaps you can help me to look into below macro coding.
    This is one of my existing workbook coding, which i used to keep track the timestamp and datestamp. Current macro code whenever you scan a barcode it will date & time stamp on column B, if duplicate barcode scan it will stamp current date & time on the next column at same row. The active cell always at column A, if active cell skip for more than one row whenever new barcode scan it will key in back to the next cell after the last data being capture.

    I hope you can help me to modify the existing code into copy related data which belongs to the code under sheet1. Just like what you have gave me the last document. Hope that you can understand my english. Thanks in advanced.



    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("A2:A3000")) Is Nothing Then Exit Sub
    If Target.Count > 1 Then Exit Sub
    If Target = "" Then Exit Sub
    Dim lc As Long, fr As Long, n As Long, nr As Long
    With Application
    .EnableEvents = False
    .ScreenUpdating = False
    n = Application.CountIf(Columns(1), Cells(Target.Row, 1))
    If n = 1 Then
    lc = Cells(Target.Row, Columns.Count).End(xlToLeft).Column
    If lc = 1 Then
    Cells(Target.Row, lc + 2) = Format(Now, "m/d/yyyy h:mm")
    ElseIf lc > 2 Then
    Cells(Target.Row, lc + 1) = Format(Now, "m/d/yyyy h:mm")
    End If
    Else
    fr = 0
    On Error Resume Next
    fr = Application.Match(Cells(Target.Row, 1), Columns(1), 0)
    On Error GoTo 0
    If fr > 0 Then
    lc = Cells(fr, Columns.Count).End(xlToLeft).Column
    Cells(fr, lc + 1) = Format(Now, "m/d/yyyy h:mm")
    Target.ClearContents
    End If
    End If
    On Error Resume Next
    Me.Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    On Error GoTo 0
    nr = Me.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    Me.Cells(nr, 1).Select
    .EnableEvents = True
    .ScreenUpdating = True
    End With
    End Sub

+ 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. Search row with criteria in all sheet, copy rows and paste in new created sheet
    By dekueb in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 08-24-2013, 01:42 PM
  2. Replies: 1
    Last Post: 03-28-2013, 02:49 PM
  3. Search 1 sheet for 4 or 5, copy that row and paste to another sheet
    By chamasp in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-17-2010, 08:07 PM
  4. Replies: 2
    Last Post: 10-15-2009, 10:12 AM
  5. Macro to search the sheet name and copy and paste the data from a major sheet
    By salma2009 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-04-2009, 02:11 AM

Tags for this Thread

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