Select Sheet in other Workbook from based on cell in selected Row

arcaidius

Board Regular
Joined
Dec 4, 2018
Messages
97
I have a workbook I enter data and have to wait for product approval before sending to a different workbook that everyone else looks at that has all the approved products. Right now I have 2 different buttons to use to send the entire row of selected cell to other workbook based on the product type in column# 10 in the selected row.

Can I consolidate these 2 buttons so that the macro pastes the row into the correct sheet based on the cell value in column # 10 in the selected row? Here is the code I have for the first sheet.

VBA Code:
Sub Button3_Click()

                         'enters date approved

Cells(Application.ActiveCell.Row, 9) = Now()

                          'enters days waited for approval

Cells(Application.ActiveCell.Row, 13) = Cells(Application.ActiveCell.Row, 9) - Cells(Application.ActiveCell.Row, 8)

Cells(Application.ActiveCell.Row, 13).NumberFormat = "0"

            'copy entire row of selected cell and paste to wb sheet 1
Selection.EntireRow.Select

Selection.CopyDim wb As Workbook

Set wb = Workbooks.Open("filename.xlsx")

wb.Worksheets("Sheet1").Select

On Error Resume Next

Dim xCell As Range

For Each xCell In ActiveSheet.Columns(1).Cells

If Len(xCell) = 0 Then

xCell.Select

Exit For

End If

Next

Selection.PasteSpecial (xlPasteValues)

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:=" filename.xlsx"

ActiveWorkbook.Close

Application.DisplayAlerts = True

End Sub
 
Last edited by a moderator:

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Well, never mind, I actually figured it out. answer was to insert the below in place of wb.Worksheets("Sheet1").Select

VBA Code:
If Cells(Application.ActiveCell.Row, 10) = "A" Then
        Set wb = Workbooks.Open("filename.xlsx")
        wb.Worksheets("A").Select
    ElseIf Cells(Application.ActiveCell.Row, 10) = "B" Then
        Set wb = Workbooks.Open("filename.xlsx")
        wb.Worksheets("B").Select
    End If
 
Last edited by a moderator:
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top