+ Reply to Thread
Results 1 to 10 of 10

how to assign the correct item code?

Hybrid View

  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.

  2. #2
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re

    Does someone interested in this question?
    Last edited by jasonlewis; 08-01-2013 at 11:13 AM.

  3. #3
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code and sort the data by item code and date?

    I have changed the questions, does someone interested?

  4. #4
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code and sort the data by item code and date?

    does someone interested in these questions?

  5. #5
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code and sort the data by item code and date?

    does someone interested in these questions?

  6. #6
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code and sort the data by item code and date?

    does someone interested in these questions?

  7. #7
    Forum Moderator jeffreybrown's Avatar
    Join Date
    02-19-2009
    Location
    Cibolo, TX
    MS-Off Ver
    Office 365
    Posts
    10,327

    Re: how to assign the correct item code and sort the data by item code and date?

    @jasonlewis,

    Your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).
    HTH
    Regards, Jeff

  8. #8
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code and sort the data by item code and date?

    Re jeffrey,

    ok.. I am asking my fd to give me the link, so that I could include the link here.
    Sorry for any inconvenience.

  9. #9
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code and sort the data by item code and date?

    I hv already add the other link from mrexcel in my post now

  10. #10
    Registered User
    Join Date
    06-29-2013
    Location
    Hong Kong
    MS-Off Ver
    Excel 2007
    Posts
    50

    Re: how to assign the correct item code?

    does someone interested in these questions?

+ 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. 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