+ Reply to Thread
Results 1 to 31 of 31

Macro creates new worksheet (already ready) but i need a little bit of data to be added

Hybrid View

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

    Re: Macro creates new worksheet (already ready) but i need a little bit of data to be adde

    Try this code. Put it in a standard module
    Option Explicit
    
    Sub copy_rows()
    Dim ws As Worksheet
    Dim lrow As Long, i As Long
    Dim sname As String
    
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Sheet1" Then ws.Delete
    Next ws
    
    With Worksheets("Sheet1")
        lrow = .Range("C" & .Rows.Count).End(xlUp).Row
        If lrow = 1 Then Exit Sub
        
        For i = 2 To lrow
            If .Range("C" & i).Interior.ColorIndex <> 43 Then
                sname = .Range("D" & i).Value
                If Not Evaluate("ISREF('" & sname & "'!A1)") Then
                    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = sname
                    .Range("C1:G1").Copy Worksheets(sname).Range("A1")
                    Worksheets(sname).Range("F1").Value = "Tp-Doc Number"
                    Worksheets(sname).Range("G1").Value = "Error Type 8"
                    Worksheets(sname).Range("H1").Value = "BA"
                End If
                .Range("C" & i & ":G" & i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                With Worksheets(sname).Range("A1:H1")
                    .Borders.LineStyle = xlContinuous
                    .Interior.ColorIndex = 23
                    .Columns.AutoFit
                    .Font.Bold = True
                End With
                
                .Range("A" & i).Hyperlinks.Add .Range("A" & i), "", "'" & sname & "'!A1", ""
            End If
        Next i
    End With
    
    Application.ScreenUpdating = True
    Application.DisplayAlerts = 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]

  2. #2
    Forum Contributor
    Join Date
    04-01-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    128

    Re: Macro creates new worksheet (already ready) but i need a little bit of data to be adde

    Dear that coloring is not proper! Can you please remove it as soon as possible thanks Rest all working fine really!

+ 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