Answer the question
In order to leave comments, you need to log in
How to insert a selection from another sheet into a sheet?
Google spreadsheet has two sheets "Tasks" and "Actions"
In "Tasks"
Fields:
Number,
Line Task
1, Make Kitchen
2, Make Room
In "Actions"
Fields: Task Number,
Line Action:
1, Order Kitchen
1, Bring a kitchen
1, Assemble a kitchen
Question - is it possible to display rows from the "Actions" sheet, where the "Task number" field has a value of 1, under the line with task number 1 in the "Tasks" sheet? If yes, how to do it?
Screenshot as I see it :) -
Answer the question
In order to leave comments, you need to log in
Sub ToDo()
Dim WB As Workbook
Dim WS_Task As Worksheet
Dim WS_Action As Worksheet
Dim TaskRowIndex As Long
Dim ActionRowIndex As Long
Set WB = Excel.ActiveWorkbook
Set WS_Task = WB.Worksheets("Задачи")
Set WS_Action = WB.Worksheets("Действия")
For TaskRowIndex = WS_Task.Rows.Count To 2 Step -1
If WS_Task.Cells(TaskRowIndex, 1) <> "" Then
Exit For
End If
Next TaskRowIndex
For ActionRowIndex = WS_Action.Rows.Count To 2 Step -1
If WS_Action.Cells(ActionRowIndex, 1) <> "" Then
Exit For
End If
Next ActionRowIndex
For TaskRow = TaskRowIndex To 1 Step -1
TaskNumber = WS_Task.Cells(TaskRow, 1)
If TaskNumber <> "" And IsNumeric(TaskNumber) Then
TaskRowShift = TaskRow + 1
For ActionRow = ActionRowIndex To 2 Step -1
If WS_Action.Cells(ActionRow, 2) = TaskNumber Then
WS_Task.Rows(Int(TaskRowShift)).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
WS_Task.Cells(TaskRowShift, 3) = WS_Action.Cells(ActionRow, 1)
WS_Task.Cells(TaskRowShift, 4) = WS_Action.Cells(ActionRow, 2)
WS_Task.Cells(TaskRowShift, 5) = WS_Action.Cells(ActionRow, 3)
End If
Next ActionRow
End If
Next TaskRow
End Sub
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question