helplessnoobatexcel
New Member
- Joined
- Dec 15, 2023
- Messages
- 45
- Office Version
- 365
- Platform
- Windows
Hi All,
Below is a code that is meant to link data in a sheet to an individual based on the column of individual names. However, this code does not run as the error is "sub not defined". Any kind soul willing to take a look at this code and help me troubleshoot it? It will be greatly apreciated ;D.
Sub LinkDataToIndividual()
Dim dataSheet As Worksheet
Dim linkedSheet As Worksheet
Dim lastDataRow As Long
Dim individualColumn As Long
Dim individualList As Range
Dim individual As Variant
Dim filterCriteria As Variant
'Set your data sheet and linked sheet'
Set dataSheet = Worksheets("Sheet5") 'Replace with your actual datasheet name'
Set linkedSheet = Worksheets("Sheet9") 'Replace with your actual linked sheet name'
'Set the column containing individual names or IDs'
individualColumn = 1 'Assuming the individual names or ID are in column 1'
'Find the last row with data in the data sheet'
last DataRow = dataSheet.Cells(dataSheet.Rows.Count, individualColumn).End(x1Up).Row
'Set the range of individual names or IDs'
Set individualList = dataSheet.Range(dataSheet.Cells(2, individualColumn), dataSheet.Cells(lastDataRow, individualColumn))
'Loop through each individual and link data'
For Each individual In individualList
'Set filter criteria based on the individual'
filterCriteria = individual.Value
'Apply filter to the data sheet'
dataSheet.Rows(1).AutoFilter Field:=individualColumn, Criteria1:=filterCriteria
'Copy visible cells (excluding header) to the linked sheet
dataSheet.UsedRange.Offset(1, 0).SpecialCells(x1CellTypeVisible).Copy linkedSheet.Cells(linkedSheet.Rows.Count, 1).End(x1Up).Offset(1, 0)
' Clear filter in the data sheet'
dataSheet.AutoFilterMode = False
Next individual
End Sub
Below is a code that is meant to link data in a sheet to an individual based on the column of individual names. However, this code does not run as the error is "sub not defined". Any kind soul willing to take a look at this code and help me troubleshoot it? It will be greatly apreciated ;D.
Sub LinkDataToIndividual()
Dim dataSheet As Worksheet
Dim linkedSheet As Worksheet
Dim lastDataRow As Long
Dim individualColumn As Long
Dim individualList As Range
Dim individual As Variant
Dim filterCriteria As Variant
'Set your data sheet and linked sheet'
Set dataSheet = Worksheets("Sheet5") 'Replace with your actual datasheet name'
Set linkedSheet = Worksheets("Sheet9") 'Replace with your actual linked sheet name'
'Set the column containing individual names or IDs'
individualColumn = 1 'Assuming the individual names or ID are in column 1'
'Find the last row with data in the data sheet'
last DataRow = dataSheet.Cells(dataSheet.Rows.Count, individualColumn).End(x1Up).Row
'Set the range of individual names or IDs'
Set individualList = dataSheet.Range(dataSheet.Cells(2, individualColumn), dataSheet.Cells(lastDataRow, individualColumn))
'Loop through each individual and link data'
For Each individual In individualList
'Set filter criteria based on the individual'
filterCriteria = individual.Value
'Apply filter to the data sheet'
dataSheet.Rows(1).AutoFilter Field:=individualColumn, Criteria1:=filterCriteria
'Copy visible cells (excluding header) to the linked sheet
dataSheet.UsedRange.Offset(1, 0).SpecialCells(x1CellTypeVisible).Copy linkedSheet.Cells(linkedSheet.Rows.Count, 1).End(x1Up).Offset(1, 0)
' Clear filter in the data sheet'
dataSheet.AutoFilterMode = False
Next individual
End Sub