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.
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