Working between workbooks and worksheets

Keysha_bee

New Member
Joined
Feb 26, 2016
Messages
19
Off to a good start but need some help finishing this...

Here's the situation: I am working between two workbooks; WB1 is used for the collection of data and although the workbook will have different data, the cells the data is entered in will remain constant, on WB2 I have 2 WSs (FPPI-Routed and Exports) and depending on the data entered in cell B3 of WB1 the data should be entered on the next available line of WB2 in the respective WS. The data that should be entered is pulled from WB1 and both WBs will be opened while the macro is running....My problem, I continue to get the the error message when the macro runs.

Code:
Sub Keysha_Bee()    Dim wb1 As Workbook
    Dim ws1 As Worksheet
    Dim wb2 As Workbook
    Dim ws2 As Worksheet
    Dim SheetID As String
    Dim i As Integer
    Dim lrow As Integer


    Set wb1 = ThisWorkbook
    Set ws1 = wb1.Sheets(1)
    Set wb2 = Workbooks("2016 Lubes Exports.xlsm")


    If InStr(ws1.Range("B3"), "Routed-FPPI") > 0 Then SheetID = "FPPI-Routed"
    If InStr(ws1.Range("B3"), "USPPI") > 0 Then SheetID = "Exports"
    If InStr(ws1.Range("B3"), "Standard") > 0 Then SheetID = "Exports"


    On Error Resume Next 'ignore any error
    Set ws2 = wb2.Worksheets(SheetID)
    On Error GoTo 0      'stop ignoring errors


    'ws2 is set
    If ws2 Is Nothing Then
        MsgBox "Sheet '" & SheetID & "' was not found!", vbExclamation
        Exit Sub
    End If


    lrow = ws2.Cells(Rows.Count, 2).End(xlUp).Row + 1
    ws2.Cells(lrow, 2) = ws1.Range("D6") 'Customer Name
    If ws2.Range("D14") = "" Then
        ws2.Cells(lrow, 3) = ws1.Range("D17") 'Agent's Name
        ws2.Cells(lrow, 4) = ws1.Range("D18") 'Auth Agent's Email
    Else
        ws2.Cells(lrow, 3) = ws1.Range("D15") 'Agent's Name
        ws2.Cells(lrow, 4) = ws1.Range("D16") 'Auth Agent's Email
    End If
    ws2.Cells(lrow, 5) = "NO" 'Routed, not sure what this is supposed to reference
    ws2.Cells(lrow, 6) = ws1.Range("D20") ' Routed
    ws2.Cells(lrow, 7) = ws1.Range("D26") ' Origin
    ws2.Cells(lrow, 8) = ws1.Range("D27") ' Hazardous
    ws2.Cells(lrow, 9) = ws1.Range("D28") ' UC Type
    ws2.Cells(lrow, 10) = "Date" 'Not sure what this is supposed to refference


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
What error(s) are you getting and where in the code are they ocurring?
 
Last edited:
Upvote 0
Are the sheet names numeric?
 
Upvote 0

Forum statistics

Threads
1,214,665
Messages
6,120,804
Members
448,990
Latest member
rohitsomani

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