Hello there,
Sorry about that I thought that was understood to place it in the exchangeddirectly worksheet by the line
2.Open the Exchangeddirectly workbook
Glad you could you get that sorted out!
As for this:
I have one more question: if the Administration file doesn't contain a sheet with the correct transporter name, the row gets deleted from the Exchanged directly file but it doesn't get copied to the Administration file. Would it be possible to skip the row in the Exchanged directly file if the transporter name (x) does not exist?
Try the below code, replacing the existing code between the Sub AddToAdmin and End Sub with the below code. What this does is if the worksheet name is not found then it highlights the cell's row black.
Let me know how it works!
Thanks!
'declare variables
Dim c As Range, LR As String, NLR As String
Dim ExWB As Workbook, AdWB As Workbook, x As String
Dim rng As Range, y As Long
Set ExWB = ThisWorkbook 'set exwb equal to the exchange directly workbook
'open the Administration workbook,
'change the below file path to your file path
Application.Workbooks.Open Filename:="C:\Documents and Settings\rvasquez\My Documents\Example Spreadsheets\Test Folder2\Administration.xls"
'set adWB equal to the Administration workbook
Set AdWB = ActiveWorkbook
With ExWB.Sheets(1) 'with the exchange workbook first worksheet in the workbook
.Activate 'activate the workbook
LR = .Range("A6555").End(xlUp).Row 'set the variable LR equal to teh last row that contains a value in column A
For Each c In .Range("A1:A" & LR + 1).Cells 'loop through cells in column A from row 1 to the last row
If c.Font.Color = RGB(255, 0, 0) Then 'if the font color in the current cell in the loop is red then
x = .Range("g" & c.Row).Value 'set x equal to value in the current cell in the loop's row in column G
.Range("A" & c.Row & ":J" & c.Row).Copy 'copy the cells from A to J of the current cell in the loop's row
On Error Resume Next
With AdWB.Sheets(x) 'with the worksheet in the Administrative workbook whose name is equal to x (defined above)
If Err.Number = 9 Then 'if the worksheet is not found then
c.EntireRow.Interior.Color = RGB(0, 0, 0) 'set the fill color of the row to black
y = 1 'set variable y = 1
Else
NLR = .Range("A6555").End(xlUp).Row + 1 'set NLR equal to the last row in column A the contains a value +1
.Range("A" & NLR).PasteSpecial xlPasteValues 'paste the copied values to the first empty cell
.Range("A" & NLR & ":J" & NLR).Font.Color = RGB(0, 0, 0) 'turn the font black
y = 0 'set variable y = 0
End If
End With
If y = 0 Then 'if y = 0 then
If rng Is Nothing Then 'if the variable rng is nothing then
Set rng = .Range(.Cells(c.Row, 1), .Cells(c.Row, 10)) 'set rng equal to cells A through J of the current row
Else: Set rng = Union(rng, .Range(.Cells(c.Row, 1), .Cells(c.Row, 10))) 'if rng does exist then set the rng equal to the current rng and add the current cell in the loops row columns A through J
End If
End If
End If
Next c 'move to next cell in the loop
.Activate
rng.Select 'select rng
Selection.Delete shift:=xlUp 'delete the rng selected
With AdWB
.Close True 'close and save the Administrative workbook
End With
End With
Bookmarks