How can i copy data to new sheets based on cell value

Status
Not open for further replies.

ashbash

New Member
Joined
Jan 4, 2019
Messages
3
I have a data sheet where there is presented Name, personal number, email etc. I have around 500 Rows with person data, that needs the data separated in different sheets sorted after names. I have color coded the persons data and the sheets to where their data should go.

I have made an vba that can make sheets with the given 500 names, but have no clue on how to copy the data to the right sheets based on the cell value with their names.

The VBa i have so far, transpose some data, and makes new sheets based of the persons names.

i have added the color coded image in the end, it shows each data belonging to each person, and what sheet the data should go, based on the names.
VBA Code:
'Transpose vice versa
Sub TransposeData()
Range("A1:O15").Value = WorksheetFunction.Transpose(Range("A1:O8"))

End Sub

Sub CreateSheets()

'Dimension variables and declare data types
Dim rng As Range
Dim cell As Range

'Enable error handling
On Error GoTo Errorhandling

'Show inputbox to user and prompt for a cell range
Set rng = Application.InputBox(Prompt:="Vælg navne til nye sheets:", _
Title:="Create sheets", _
Default:=Selection.Address, Type:=8)

'Iterate through cells in selected cell range
For Each cell In rng

    'Check if cell is not empty
    If cell <> "" Then

        'Insert worksheet and name the worksheet based on cell value
        Sheets.Add.Name = cell
    End If

'Continue with next cell in cell range
Next cell

'Go here if an error occurs
Errorhandling:

'Stop macro
End Sub

Public Sub Testing()

Dim i As Long
Dim copyFrom As String
copyFrom = "Ark1"

For i = 1 To Sheets.Count
    If Sheets(i).Name <> copyFrom Then
        Sheets(copyFrom).Columns(1).Copy Destination:=Sheets(i).Columns(1)
    End If
Next i

End Sub


Udklip.PNG
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Status
Not open for further replies.

Forum statistics

Threads
1,223,958
Messages
6,175,643
Members
452,663
Latest member
MEMEH

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