OK first off, assigning a macro...
In Excel go to Insert>Shapes and pick a shape and draw it somewhere
Right-click the shape you have drawn and you will see an 'Assign a Macro' option, click that and choose your macro from the list, click OK
If you want a keyboard short-cut instead or as well, in Excel hit ALT+F8, this will bring up the Macros window, can also be found under Tools>Macros>Macros in 2003 and earlier or View>Macros in 2007 onwards
Click the 'Options' button and assign whatever key you want to use to it, then click OK
Note, most Ctrl shortcuts already have a function, e.g. Ctrl+A is select all, Ctrl+P is print, Ctrl+X, Ctrl+C, Ctrl+V are cut, copy, paste respectively, and the list goes on, so I recommend you don't use any of these commands, I would use Ctrl+Shift+(Any key).
As for the separating of the suppliers, you will need to build a list of what relates to supplier 1 and supplier 2, then use that list to find which one the current row relates to. This example assumes it's the Company name (Column B) that decides which it belongs to:
Sub UpdateSuppliers()
Const Supplier1Companies as String = "{ABC Ltd}{MNO Ltd}{XYZ Ltd}"
Const Supplier2Companies as String = "{DEF Ltd}{PQR Ltd}{XYZ Ltd}"
Dim iRo As Integer, NumCols As Integer, NumRow1 As Integer, NumRow2 As Integer
Dim CompSht As Worksheet, Sup1Sht As Worksheet, Sup2Sht As Worksheet
Set CompSht = Sheets("CompanyA")
Set Sup1Sht = Sheets("Supplier1")
Set Sup2Sht = Sheets("Supplier2")
NumRow1 = Sup1Sht.Cells(Sup1Sht.Rows.Count, 1).End(xlUp).Row + 1
NumRow2 = Sup2Sht.Cells(Sup2Sht.Rows.Count, 1).End(xlUp).Row + 1
If ActiveWorkbook.ActiveSheet <> CompSht Then Exit Sub
iRo = ActiveCell.Row
NumCols = 6
If InStr(1, Supplier1Companies, "{" & CompSht.Cells(iRo, 2).Value & "}") > 0 Then
For i = 1 To NumCols
'Input data...
Sup1Sht.Cells(NumRow1, i).Value = CompSht.Cells(iRo, i).Value
Next
End If
If InStr(1, Supplier2Companies, "{" & CompSht.Cells(iRo, 2).Value & "}") > 0 Then
For i = 1 To NumCols
'Input data...
Sup2Sht.Cells(NumRow2, i).Value = CompSht.Cells(iRo, i).Value
Next
End If
End Sub
That should do the trick. If in this example you had ABC Ltd on the line, it would go only to Supplier 1 sheet, if you had DEF Ltd, will only go to Supplier 2 sheet, if you had XYZ Ltd, it would go to both. As always, ask if you need to follow up on any of this.
Regards, Dai
------------------------------------------
Do or do not, there is no try. |
------------------------------------------