0
votes

I'm VBA noobs and in need to finish my assignment.

I would like to copy a template worksheets into and copy some cell automatically to it.
Here's what I get from webs, and I'm stuck now..

Sub CopyTemplate()
    Dim myCell As Range, MyRange As Range, Orange As Range
    Set MyRange = Sheets("Isolation Section").Range("B24")
    Set MyRange = Range(MyRange, MyRange.End(xlDown))
    Set Orange = Sheets("Isolation Section").Range("D24")
    Set Orange = Range(MyRange, MyRange.End(xlDown))

    Application.ScreenUpdating = False
    For Each myCell In MyRange
        Sheets("Template").Copy After:=Sheets(Sheets.Count)
        With myCell
            ActiveSheet.Name = .Value
            ActiveSheet.Range("A13").Value = .Value
            ActiveSheet.Range("E13").Value = Orange.Value
            .Parent.Hyperlinks.Add Anchor:=myCell, Address:="", SubAddress:= _
               "'" & .Text & "'!B24", TextToDisplay:=.Text
        End With
    Next myCell
    Application.ScreenUpdating = True
End Sub

I have a template sheet called Template.
I create a copy of Template sheet and name it after each row from Isolation Section (so a loop).
Then place the cell data row B24 in cell A13 of the sheet.
But how about the cell data row D24 from Isolation Section copied to each sheets in new worksheets cell E13?

Image:

Sample Image

Sorry if my English is bad..

2
Your code doesn't add up. First, you need to remove copying the Template worksheet in your loop. Second, you need to clarify what changes you need to make in the newly copied Template worksheet. Clarify your question and specifically point out what's not working. As is now, it is unclear.L42
In your edit, you never set the variable Orange. Also I think it is worth adding a screen shot or illustration of what you want to achieve.L42
i cannot add the screen shot, my reputation not enough.. T.Tkireta7
Just post the link and I'll do it for you. Just upload it in a free image hosting website like this one: i.imgur.comL42
imgur.com/WCmC7i1 , i just want Description row to automatically copied to green highlightkireta7

2 Answers

0
votes

Try this:

For Each mycell In MyRange
    Sheets("Template").Copy After:=Sheets(Sheets.Count)
    With ActiveSheet
        .Name = mycell
        .Range("A1").Value = mycell.value
        .Range("E1").Value = mycell.Offset(0, 1).Value
    End With
    mycell.Parent.Hyperlinks.Add Anchor:=myCell, Address:="", SubAddress:= _
        "'" & mycell.Text & "'!B24", TextToDisplay:=mycell.Text
Next
0
votes

Your description isn't very clear, but the easiest way to resolve your issue would be to just use macro recorder and copy and paste the code.

Here's microsoft's site on how to create/delete one: http://office.microsoft.com/en-us/excel-help/create-or-delete-a-macro-HP010342374.aspx

I create macros sometimes and as long as you know something about coding, you can just glue together a couple of macro recordings and have a working macro... that's actually standardised. Good luck.