Help in incorporating a code in to the final code

Hi All,  If I could get some help in incorporating the below code to the final code(In bold) that would great. The ranges should not be hard coded like I did in the example below as it is going to Vary.Basically trying to copy the two columns of "Forms Tab" into "Table of contents Tab".

Sub OneCell()
    Worksheets("Table of Contents").Range("A9:A50").Value = Worksheets("Forms").Range("C2:C42").Value
    Worksheets("Table of Contents").Range("B9:B50").Value = Worksheets("Forms").Range("A2:A42").Value
End Sub


Final Code:


Sub createWorksheets()

    Dim r As Long, TemplateWS As Worksheet
    Set TemplateWS = Worksheets("Template Tab")
    For r = 2 To Worksheets("Forms").Cells(Rows.Count, "A").End(xlUp).Row
        If Worksheets("Forms").Cells(r, "D") = True Then
            TemplateWS.Copy after:=Worksheets(Worksheets.Count)
            ActiveSheet.Name = Worksheets("Forms").Cells(r, "A")
        End If
    Next
   
End Sub
Milind AgarwalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roy CoxGroup Finance ManagerCommented:
An example workbook would be helpful
1
Milind AgarwalAuthor Commented:
Just updated the attachment.
Basically trying to copy the two columns of "Forms Tab" into "Table of contents Tab" When its TRUE in ColD (Forms Tab)

Sub OneCell()
    Worksheets("Table of Contents").Range("A9:A50").Value = Worksheets("Forms").Range("C2:C42").Value
    Worksheets("Table of Contents").Range("B9:B50").Value = Worksheets("Forms").Range("A2:A42").Value
End Sub
Table-of-Contents-Tab.xlsx
0
Martin LissOlder than dirtCommented:
Did you want something in the "Comments" column?

Sub CopyToTOC()
Dim lngLastRow As Long
Dim lngRow As Long
Dim wsFrom As Worksheet
Dim wsTo As Worksheet
Dim lngNextRow As Long

Set wsFrom = Sheets("Forms")
Set wsTo = Sheets("Table of Contents")

With wsFrom
    lngLastRow = .Range("A1048576").End(xlUp).Row
    lngNextRow = 9
    
    For lngRow = 2 To lngLastRow
        If UCase(.Cells(lngRow, "D")) = "TRUE" Then
            wsTo.Cells(lngNextRow, "A") = .Cells(lngRow, "C")
            wsTo.Cells(lngNextRow, "B") = .Cells(lngRow, "A")
            lngNextRow = lngNextRow + 1
        End If
    Next
End With
End Sub

Open in new window

1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
1
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.