Home |
Search |
Today's Posts |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try this, which I could not test.
HTH -- AP '------------------------------------------------ Private Sub CommandButton1_Click() Const sSalesSheetName As String = "Ark1" Const sCellToWriteIn As String = "AF3" Dim salesFile(1 To 5) salesFile(1) = "C:\180.xls" salesFile(2) = "C:\180.xls" salesFile(3) = "C:\200.xls" salesFile(4) = "C:\210.xls" salesFile(5) = "C:\250.xls" Dim iSalesNo As Integer Dim wkbNew As Excel.Workbook Dim wkbSales As Excel.Workbook Dim wksImport As Excel.Worksheet Dim wksView As Excel.Worksheet Dim lRowFrom As Long Dim lRowTo As Long Dim bFound As Boolean 'On Error GoTo CleanUp Set wkbNew = ActiveWorkbook Set wksImport = wkbNew.ActiveSheet For iSalesNo = LBound(salesFile) To UBound(salesFile) Set wkbSales = Application.Workbooks.Open( _ Filename:=salesFile(iSalesNo)) Set wksView = wkbSales.Worksheets(sSalesSheetName) ' 2-tallet her bestemmer hvilken ' række det første kundenr findes i( Update-filen) For lRowFrom = 2 To wksImport.UsedRange.Rows.Count bFound = False ' 3-tallet her bestemmer hvilken række ' det første kundenrfindes i(Salgsview - filen) For lRowTo = 3 To wksView.UsedRange.Rows.Count If Val(wksImport.Cells(lRowFrom, 1).Value) = _ wksView.Cells(lRowTo, 2).Value Then wksView.Cells( _ lRowTo, _ wksView.Range(sCellToWriteIn).Column _ ).Value = _ wksImport.Cells(lRowFrom, 2).Value bFound = True Exit For End If Next lRowTo If Not bFound Then 'Cellen bliver rød, 'hvis ikke den er overført til opsummeringsarket wksImport.Cells(lRowFrom, 1).Interior.ColorIndex = 3 End If Next lRowFrom Next iSalesNo CleanUp: Set wksImport = Nothing Set wksView = Nothing Set wkbNew = Nothing Set wkbSales = Nothing End Sub "Alen32" a écrit dans le message de ... Hej! I have makro which open and update file 150.xls and makro works well. I need to change makro so I can update at same time files 180.xls, 200.xls, 210.xls, 250.xls and 300.xls. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Use Macro To Change Which Macro Assigned To Command Button | Excel Discussion (Misc queries) | |||
Insert row at change macro - how to change it. | Excel Discussion (Misc queries) | |||
macro that will change the font of a cell if i change a value | Excel Discussion (Misc queries) | |||
Cell value change to trigger macro (worksheet change event?) | Excel Programming | |||
Macro to change Macro code? | Excel Programming |