Results 1 to 10 of 10

how to assign the correct item code?

Threaded View

jasonlewis how to assign the correct... 07-31-2013, 12:24 PM
jasonlewis Re 07-31-2013, 09:59 PM
jasonlewis Re: how to assign the correct... 08-01-2013, 11:13 AM
jasonlewis Re: how to assign the correct... 08-01-2013, 09:42 PM
jasonlewis Re: how to assign the correct... 08-02-2013, 11:44 AM
jasonlewis Re: how to assign the correct... 08-03-2013, 07:40 AM
jeffreybrown Re: how to assign the correct... 08-03-2013, 10:00 AM
jasonlewis Re: how to assign the correct... 08-03-2013, 01:31 PM
jasonlewis Re: how to assign the correct... 08-04-2013, 01:24 AM
jasonlewis Re: how to assign the correct... 08-04-2013, 10:28 PM
  1. #1
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    how to assign the correct item code?

    Halo,anyone.
    I would like to ask how to assign the correct item code for each record in template2?
    It is because when I search 1/7/2013-15/7/2013, it output 4 records,
    but the item code is not 1,2,3,4. How can I assign it correctly?

    Thanks, jason.

    Option Explicit
    Private Sub CommandButton1_Click()
     Dim ws As Worksheet
     Set ws1 = Sheets("Template2")
     Set ws2 = Sheets("Database2")
     Set ws3 = Sheets("By Period")
     Dim i As Integer
     Dim j As Integer
      
     For i = 2 To ws2.Cells(Rows.Count, 1).End(xlUp).row
     If ws3.Cells(7, 3).Value >= ws2.Cells(i, 2).Value And ws3.Cells(4, 3).Value <= ws2.Cells(i, 2).Value And ws2.Cells(i, 9).Value = 0 Then
    
     LR = ws1.Range("B" & Rows.Count).End(xlUp).row
     
     ws1.Range("A" & LR + 1) = i - 1
    
     ws2.Cells(i, 2).Copy
     ws1.Range("B" & LR + 1).PasteSpecial Paste:=xlPasteValues
     ws1.Range("B" & LR + 1).NumberFormat = "dd/mm/yyyy"
     
     ws2.Cells(i, 3).Copy
     ws1.Range("C" & LR + 1).PasteSpecial Paste:=xlPasteValues
     
     ws2.Cells(i, 4).Copy
     ws1.Range("D" & LR + 1).PasteSpecial Paste:=xlPasteValues
     
     ws2.Cells(i, 8).Copy
     ws1.Range("E" & LR + 1).PasteSpecial Paste:=xlPasteValues
     
     ws2.Cells(i, 5).Copy
     ws1.Range("F" & LR + 1).PasteSpecial Paste:=xlPasteValues
     
     ws2.Cells(i, 14).Copy
     ws1.Range("G" & LR + 1).PasteSpecial Paste:=xlPasteValues
     
     ws2.Cells(i, 6).Copy
     ws1.Range("H" & LR + 1).PasteSpecial Paste:=xlPasteValues
     
     ws2.Cells(i, 12).Copy
     ws1.Range("I" & LR + 1).PasteSpecial Paste:=xlPasteValues
      
     ws2.Cells(i, 13).Copy
     ws1.Range("J" & LR + 1).PasteSpecial Paste:=xlPasteValues
     ws1.Range("J" & LR + 1).NumberFormat = "dd/mm/yyyy"
      
     ws2.Cells(i, 11).Copy
     ws1.Range("K" & LR + 1).PasteSpecial Paste:=xlPasteValues
      
     End If
     
     Next i
     
      Dim xlSort As XlSortOrder
      
      With ws1
    
         LR = ws1.Range("B" & Rows.Count).End(xlUp).row
            
               If (.Range("C6").Value > .Range("C" & CStr(LR))) Then
                 xlSort = xlDescending
             Else
                 xlSort = xlAscending
             End If
           
            .Range("B6:K" & LR).Sort Key1:=.Range("C6"), Order1:=xlSort, Header:=xlNo, _
                OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
                DataOption1:=xlSortNormal
        
         End With
         
         ActiveWorkbook.Save
    
         
    End Sub
    Same post by hei,

    http://www.mrexcel.com/forum/excel-q...code-date.html
    Attached Files Attached Files
    Last edited by jasonlewis; 08-16-2013 at 04:17 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Form produce search result on preview webbrouser
    By savyback in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-08-2013, 04:19 PM
  2. Form to Search (selected columns) and display result
    By vairam in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2013, 11:27 AM
  3. how to use VBA to search and return search result in the user form
    By pearlynie in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-25-2013, 07:58 AM
  4. Need a help to create a search result form
    By naaf2012 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-05-2012, 01:41 AM
  5. How to use Form to Find and Display Search Result
    By xinzie in forum Excel General
    Replies: 1
    Last Post: 03-28-2009, 05:46 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