LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Change Macro

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use Macro To Change Which Macro Assigned To Command Button CVinje Excel Discussion (Misc queries) 0 May 25th 10 09:55 PM
Insert row at change macro - how to change it. cathit Excel Discussion (Misc queries) 1 March 26th 09 07:14 PM
macro that will change the font of a cell if i change a value jk Excel Discussion (Misc queries) 2 July 29th 08 04:39 PM
Cell value change to trigger macro (worksheet change event?) Neil Goldwasser Excel Programming 4 January 10th 06 01:55 PM
Macro to change Macro code? Kaisies Excel Programming 2 March 23rd 05 03:34 AM


All times are GMT +1. The time now is 07:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"