Const dataSamlerSti = "F:\Regnskab\Statusark\" Const dataSamlerFilNavn = "Statusliste 2015.xlsm" Dim dataSamler As Object Private Sub CommandButton1_Click() Dim produktId, rækDs As Integer Set produkt = ActiveWorkbook
produktId = Range("B5")
Set dataSamler = CreateObject("Excel.Application") dataSamler.Workbooks.Open dataSamlerSti & dataSamlerFilNavn
rækDs = findRækkeDataSamler(produktId) If rækDs > 0 Then kopierData rækDs dataSamler.ActiveWorkbook.Save Else MsgBox "ProduktId ikke fundet" End If
dataSamler.Quit Set dataSamler = Nothing End Sub Private Function findRækkeDataSamler(produktId) Dim antalRækker As Integer antalRækker = dataSamler.ActiveCell.SpecialCells(xlLastCell).Row
With dataSamler.Sheets(dataSamlerArkNavn) dataSamler.Sheets(dataSamlerArkNavn).Activate
For Each CC In .Range("B5:B" & antalRækker) If produktId = CC Then findRækkeDataSamler = CC.Row Exit Function End If Next CC End With findRækkeDataSamler = 0 End Function Private Sub kopierData(rækDs) With dataSamler.Sheets(dataSamlerArkNavn) .Range("L" & rækDs) = produkt.Sheets(1).Range("Udsendt_budgopf3") .Range("M" & rækDs) = produkt.Sheets(1).Range("resultat_budgopf3") .Range("N" & rækDs) = produkt.Sheets(1).Range("SvarDato_budgopf3") .Range("O" & rækDs) = produkt.Sheets(1).Range("rykkerbrev1_budgopf3") .Range("P" & rækDs) = produkt.Sheets(1).Range("rykkerbrev2_budgopf3") .Range("Q" & rækDs) = produkt.Sheets(1).Range("kodefelt_budgopf3") .Range("X" & rækDs) = produkt.Sheets(1).Range("SendtMakker_3") .Range("Y" & rækDs) = produkt.Sheets(1).Range("ReturMakker_3")
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.