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.
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