+ Reply to Thread
Results 1 to 5 of 5

VBA Help one sheet data spread in multisheets by employee code

Hybrid View

  1. #1
    Registered User
    Join Date
    08-23-2012
    Location
    Ahmedabad,India
    MS-Off Ver
    Excel 2007
    Posts
    12

    Post VBA Help one sheet data spread in multisheets by employee code

    Dear Sir,

    Please find the attached file ,

    In this workbook 1 sheet is a data entry sheet . you will find in column 3 as a employee code , and other sheets name defined as employee code :

    when i run macro then data spread to other sheets by employee code .

    But problem is that ... when i click to run macro sheet name : 1,2,3 rows increasing . it should not to be .

    so can u help me .
    Attached Files Attached Files
    From :
    Sa.1985

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: VBA Help one sheet data spread in multisheets by employee code

    Try this code
    Sub copy_data()
    Dim i As Long, lrow As Long
    Dim sname As String
    
    Application.ScreenUpdating = False
    
    For i = 1 To Worksheets.Count
        With Worksheets(i)
            If .Name <> "Data entry" Then
                lrow = .Range("A" & .Rows.Count).End(xlUp).Row
                If lrow > 1 Then .Range("A2:G" & lrow).ClearContents
            End If
        End With
    Next i
    
    With Worksheets("Data entry")
        lrow = .Range("B" & .Rows.Count).End(xlUp).Row
        For i = 2 To lrow
            sname = .Range("C" & i).Value
            If Not Evaluate("ISREF('" & sname & "'!A1)") Then
                Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = sname
                .Rows("1:1").Copy Worksheets(sname).Range("A1")
            End If
            .Range("A" & i & ":G" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        Next i
    End With
    
    MsgBox "Data transferred"
    
    Application.ScreenUpdating = True
    
    End Sub
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    08-23-2012
    Location
    Ahmedabad,India
    MS-Off Ver
    Excel 2007
    Posts
    12

    Re: VBA Help one sheet data spread in multisheets by employee code

    Thank you so much
    arlu1201 & also thanks to VBA forum team .

  4. #4
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: VBA Help one sheet data spread in multisheets by employee code

    @ sa.1985

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  5. #5
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: VBA Help one sheet data spread in multisheets by employee code

    For those who prefer to use VBA:

    Sub snb()
      sn = Sheets("Data entry").Cells(1).CurrentRegion
    
      For j = 2 To UBound(sn)
        If sn(j, 3) <> "" Then Sheets(Format(sn(j, 3))).Cells(Rows.Count, 1).End(xlUp).Offset(1).Resize(, UBound(sn, 2)) = Application.Index(sn, j)
      Next
    End Sub



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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