My code is using two worksheets. I want the code to read the offset number on tab A and insert the approrpriate rows. I then want it to read from a list of records on tab B and copy and paste data from Columns D and E when the ID Codes are matched (Column D in TAB A and Column B in TAB B)
I've pasted my code below. I get an error stating: 'Subscript out of range' at the point in my code where I want to "'Find applicable ID number in the list of IDs". Any ideas? Thanks.
The layout of Tab A and Tab B are as follows:
TAB A
ColumnA ColumnB ColumnC ColumnD Column E
Data Data Data ID Code Offset
TAB B
ColumnA ColumnB ColumnC ColumnD ColumnE
Data Range ID.code2 Offset Data Data
My Current Code
Sub FormatRM()
Dim Cell As Range
Set Cell = Sheets("RM Planning").Range("E4")
Do While Not IsEmpty(Cell)
If Cell > 1 Then
'Insert additional rows based on the offset amount
Range(Cell.Offset(1, 0), Cell.Offset(Cell.Value - 1, 0)).EntireRow.Insert
With Sheets("ID Library").Range("ID.code2")
'Find applicable ID number in the list of IDs
Cells.Find(What:=Cell.Offset(0, -1), After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
'Copy the required set of job plans for the asset
Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(Cell.Value - 1, 3)).Copy
Cell.Offset(0, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End With
Range(Cell.Offset(0, -1), Cell.Offset(Cell.Value - 1, 0)).Columns.FillDown
End If
Set Cell = Cell.Offset(Cell.Value, 0)
Loop
End Sub
<!-- / message -->
I've pasted my code below. I get an error stating: 'Subscript out of range' at the point in my code where I want to "'Find applicable ID number in the list of IDs". Any ideas? Thanks.
The layout of Tab A and Tab B are as follows:
TAB A
ColumnA ColumnB ColumnC ColumnD Column E
Data Data Data ID Code Offset
TAB B
ColumnA ColumnB ColumnC ColumnD ColumnE
Data Range ID.code2 Offset Data Data
My Current Code
Sub FormatRM()
Dim Cell As Range
Set Cell = Sheets("RM Planning").Range("E4")
Do While Not IsEmpty(Cell)
If Cell > 1 Then
'Insert additional rows based on the offset amount
Range(Cell.Offset(1, 0), Cell.Offset(Cell.Value - 1, 0)).EntireRow.Insert
With Sheets("ID Library").Range("ID.code2")
'Find applicable ID number in the list of IDs
Cells.Find(What:=Cell.Offset(0, -1), After:=.Cells(1, 1), LookIn:=xlFormulas, LookAt _
:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
'Copy the required set of job plans for the asset
Range(ActiveCell.Offset(0, 2), ActiveCell.Offset(Cell.Value - 1, 3)).Copy
Cell.Offset(0, 1).PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End With
Range(Cell.Offset(0, -1), Cell.Offset(Cell.Value - 1, 0)).Columns.FillDown
End If
Set Cell = Cell.Offset(Cell.Value, 0)
Loop
End Sub
<!-- / message -->