H
Hinojosa via OfficeKB.com
Attached is my currect macro is adding two characters in the front would it
be possible to add three characters in the back also?
Sub Goodman2()
Const Summaryworkbook = "GOODMAN OPEN ITEMS.xls"
Const MainInvoiceCol = 2
Const MainPasteCol = 22
Const wbkInvoiceCol = 5
Const wbkStartCol = 1
Const wbkEndCol = 14
Dim i As Integer
Set wsh1 = Workbooks(Summaryworkbook).Worksheets(1)
wsh1.Activate
Lastrow = wsh1.Cells(Rows.Count, MainInvoiceCol).End(xlUp).Row
Set InvoiceRange = wsh1. _
Range(Cells(1, MainInvoiceCol), Cells(Lastrow, MainInvoiceCol))
For Each cell1 In InvoiceRange
InvoiceNumber = cell1.Value
i = Len(InvoiceNumber)
i = i + 2
InvoiceNumber = Right(InvoiceNumber, i)
For Each wbk1 In Application.Workbooks
If StrComp(wbk1.Name, Summaryworkbook) <> 0 Then
With wbk1.Worksheets(1)
.Activate
Lastrow = .Cells(Rows.Count, wbkInvoiceCol).End(xlUp).Row
Set InvoiceRange2 = .Range(Cells(1, wbkInvoiceCol), Cells(Lastrow,
wbkInvoiceCol))
For Each Cell2 In InvoiceRange2
If (Cell2.Value = "CM" & InvoiceNumber) Then
.Range(Cells(Cell2.Row, wbkStartCol), _
Cells(Cell2.Row, wbkEndCol)).Copy _
Destination:=wsh1.Cells(cell1.Row, MainPasteCol)
End If
Next Cell2
End With
End If
Next wbk1
Next cell1
End Sub
be possible to add three characters in the back also?
Sub Goodman2()
Const Summaryworkbook = "GOODMAN OPEN ITEMS.xls"
Const MainInvoiceCol = 2
Const MainPasteCol = 22
Const wbkInvoiceCol = 5
Const wbkStartCol = 1
Const wbkEndCol = 14
Dim i As Integer
Set wsh1 = Workbooks(Summaryworkbook).Worksheets(1)
wsh1.Activate
Lastrow = wsh1.Cells(Rows.Count, MainInvoiceCol).End(xlUp).Row
Set InvoiceRange = wsh1. _
Range(Cells(1, MainInvoiceCol), Cells(Lastrow, MainInvoiceCol))
For Each cell1 In InvoiceRange
InvoiceNumber = cell1.Value
i = Len(InvoiceNumber)
i = i + 2
InvoiceNumber = Right(InvoiceNumber, i)
For Each wbk1 In Application.Workbooks
If StrComp(wbk1.Name, Summaryworkbook) <> 0 Then
With wbk1.Worksheets(1)
.Activate
Lastrow = .Cells(Rows.Count, wbkInvoiceCol).End(xlUp).Row
Set InvoiceRange2 = .Range(Cells(1, wbkInvoiceCol), Cells(Lastrow,
wbkInvoiceCol))
For Each Cell2 In InvoiceRange2
If (Cell2.Value = "CM" & InvoiceNumber) Then
.Range(Cells(Cell2.Row, wbkStartCol), _
Cells(Cell2.Row, wbkEndCol)).Copy _
Destination:=wsh1.Cells(cell1.Row, MainPasteCol)
End If
Next Cell2
End With
End If
Next wbk1
Next cell1
End Sub