VBA - create new Sheet + fill data in cell based on list

WouzzieW

New Member
Joined
Apr 5, 2016
Messages
1
Hi,

I have a VBA script running to add a new Sheet, fill it with a template (TEST Test2) and add the name of the specific employee based on a list.
The employee data is located on worksheet RRAV, column K provides the name of the employee.

What i want to do is populate cell B3 with the user code (RRAVcode) of the employee (column A in the RRAV worksheet).

To do so, i tried to add the 'Sheets(Sheets.Count).Range("B3") = RRAVcodes.Value' line, but this populates all user worksheets with the first user code in the list.

Any help is appreciated!

Code:
Sub CreateSheetsFromAList()
    Dim MyCell As Range, myRange As Range, RRAVcodes As Range
    Dim wsNew As Worksheet
     
    Set myRange = Sheets("RRAV").Range("K1")
    Set myRange = Range(myRange, myRange.End(xlDown))
    
    Set RRAVcodes = Sheets("RRAV").Range("A1")
    Set RRAVcodes = Range(RRAVcodes, RRAVcodes.End(xlDown))

    For Each MyCell In myRange
        Worksheets("Test TEST2").Copy after:=Sheets(Sheets.Count)
        Sheets(Sheets.Count).Name = MyCell.Value
        Sheets(Sheets.Count).Range("B3") = RRAVcodes.Value
                        
    Next MyCell
    
    End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.

Forum statistics

Threads
1,221,467
Messages
6,160,018
Members
451,611
Latest member
PattiButche

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top