I have s excel sheet with a couple of input sheets, where different input values are shown. In all these input sheets, dates are shown in column A (starting at A6) and client names are shown in each column in row 4, starting at B4 (around 600 names, and these can increase when new input is imported). In the range between these dates and client lists, quantities are shown. Now i want to multiply the values from these input sheets into one data sheet. The data sheet (output sheet) has the same format as the input sheets, so dates are shown in column A and clients names are shown in Row 4. These are copied from one of the input sheets so the data sheet has the same format. I only want to multiply the values of four of the input sheets, IF the dates in colomn A ar equal AND the client names in row 4 are equal. It is important to note that dates can vary among the different input sheets, and therefore I think I should use the find function, so that only the values with equal dates and client names are multiplied. I have a problem with making a working module in VBA. I now have the following:
Option Explicit
Sub PriceQuantityFactRent()
'Declare Variables
Dim i, r, c, count, lastColData, LastRowData, lastRowInput, startSearch As Integer
Dim shtData, shtInputI, shtInputII, shtInputIII, shtInputIV, shtCopy As Worksheet
Set shtData = Sheets("PQFR")
Set shtInputI = Sheets("INPUTCP")
Set shtInputII = Sheets("INPUTR")
Set shtInputIII = Sheets("FACTOREN")
Set shtInputIV = Sheets("QNOMINAL")
Set shtCopy = Sheets("INPUTR")
lastColData = shtData.Cells(2, shtData.Columns.count).End(xlToLeft).Column
LastRowData = shtData.Cells(shtData.Rows.count, "A").End(xlUp).Row
lastRowInput = shtInputI.Cells(shtInputI.Rows.count, "A").End(xlUp).Row
'lastRowData = 10
'Copy ISIN codes and Dates from input sheet : These variables should be added before the loop starts : So this will be macro 1
shtCopy.Range("A4:XFD4").Copy Destination:=shtData.Range("A4:XFD4")
shtCopy.Range("A4:A" & lastRowInput).Copy Destination:=shtData.Range("A4:A" & lastRowInput)
shtData.Range("A6:A" & LastRowData).NumberFormat = "dd/mm/yyyy"
'Search starting from which row?
startSearch = InputBox("Vanaf welke rij wil je zoeken?", "Start", Default:=6)
'Loop Code
For r = startSearch To LastRowData
For c = 2 To lastColData
count = 0
If shtInputI.Cells.Find(What:=shtInputI.Cells(r, 1).Value, LookAt:=xlWhole, Searchorder:=xlByRows, SearchDirection:=xlNext) = shtData.Cells(r, 1).Value And _
shtInputII.Cells.Find(What:=shtInputII.Cells(r, 1).Value, LookAt:=xlWhole, Searchorder:=xlByRows, SearchDirection:=xlNext) = shtData.Cells(r, 1).Value And _
shtInputIII.Cells.Find(What:=shtInputIII.Cells(r, 1).Value, LookAt:=xlWhole, Searchorder:=xlByRows, SearchDirection:=xlNext) = shtData.Cells(r, 1).Value And _
shtInputIV.Cells.Find(What:=shtInputIV.Cells(r, 1).Value, LookAt:=xlWhole, Searchorder:=xlByRows, SearchDirection:=xlNext) = shtData.Cells(r, 1).Value Then
If shtInputI.Cells.Find(What:=shtInputI.Cells(4, c).Value, LookAt:=xlWhole, Searchorder:=xlByColumns, SearchDirection:=xlNext) = shtData.Cells(4, c).Value And _
shtInputII.Cells.Find(What:=shtInputII.Cells(4, c).Value, LookAt:=xlWhole, Searchorder:=xlByColumns, SearchDirection:=xlNext) = shtData.Cells(4, c).Value And _
shtInputIII.Cells.Find(What:=shtInputIII.Cells(4, c).Value, LookAt:=xlWhole, Searchorder:=xlByColumns, SearchDirection:=xlNext) = shtData.Cells(4, c).Value And _
shtInputIV.Cells.Find(What:=shtInputIV.Cells(4, c).Value, LookAt:=xlWhole, Searchorder:=xlByColumns, SearchDirections:=xlNext) = shtData.Cells(4, c).Value Then
count = count + ((shtInputI.Cells(r + 2, c).Value) / 100) * shtInputIV.Cells(r, 2).Value * shtInputIII.Cells(r, 2).Value * (1 + (shtInputII.Cells(r + 2, 2).Value / 100))
End If
End If
shtData.Cells(r, c).Value = count + shtData.Cells(r - 1, c).Value
Next c
Next r
'Formatting shtData.Range("B4:XFD" & LastRowData).NumberFormat = "0.00"
End Sub
Can someone please help to get the macro to work? VBA does not give an error, but no outcomes are shown.
Aucun commentaire:
Enregistrer un commentaire