Home > Net >  Move Worksheet based off a cell value to another workbook
Move Worksheet based off a cell value to another workbook

Time:09-27

I'm hoping someone can help with this but I'm having the darnest time getting anything to work. I have a rather large workbook with lots of worksheets, I have a report that runs and populates Column B with a "trigger" Column A: is the name of all the worksheets in the workbook. Column B is the indicator that the specific worksheet needs to be moved, e.g. "Yes". I need to move the specified workbook into another workbook.

I can only find applicable examples for moving cells but it didn't work. Any help or direction will be greatly appreciated!

CodePudding user response:

Maybe a for each loop would be good.

Dim wkbk1 As Workbook - Main workbook Dim wkbk2 As Workbook - Your other workbook

Set wkbk1 = ActiveWorkbook Set wkbk2 = "input name here"

Dim ws As Worksheet

For Each ws In wkbk1.Sheets

'use if code to check if certain Criteria met' ws.Move wkbk2.Sheets(Sheets.Count)

Next ws

CodePudding user response:

I would have one loop to run through column A and check if the sheet needs to be move by checking the column B right alongside it. If column B contains the trigger, which would be checked with a if condition, then move the sheet to another workbook.

For i = 1 To Sheets("Sheet1").End(xlDown).Row

If Sheets("sheet1").Range("B" & i) = "Yes" Then

Sheets(Sheets("sheet1").Range("A" & i)).Move After:=Workbooks("Otherworkbook.xls").Sheets(1)

Else

End If

Next i

Something like this but might need to declare the second workbook with the full filename and directory.

  • Related