I need to create calculations for about 150 products, each of which consists of about 50-60 sub-products. Depending whether the sub-product is produced or bought in from an external source, the price would be calculated differently. Essentially I need to copy-paste the weight and price for each sub-product included in the product and determine what the source is.
I would like excel to look at previously made calculations in the same folder (all different workbooks) and if it finds a cell in one of the workbooks, then to copy-paste the weight, price and source to the currently open workbook. I'm completely lost as to how to compare the cells and if a match is found, then copy that to the right place. I believe .Find and .FindNext could be useful here, but I'm not entirely sure how to use them.
Below is an example of how my data is structured:
And this is what I've found so far:
Sub RunCodeOnAllXLSFiles()
Dim lCount As Long
Dim wbResults As Workbook
Dim wbCodeBook As Workbook
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.EnableEvents = False
On Error Resume Next
Set wbCodeBook = ThisWorkbook
With Application.FileSearch
.NewSearch
'Change path to suit
.LookIn = "C:\ahjualune\stuff"
.FileType = msoFileTypeExcelWorkbooks
'Optional filter with wildcard
.Filename = "*NAV*.xls*"
If .Execute > 0 Then 'Workbooks in folder
For lCount = 1 To .FoundFiles.Count 'Loop through all
'Open Workbook x and Set a Workbook variable to it
Set wbResults = Workbooks.Open(Filename:=.FoundFiles(lCount), UpdateLinks:=0)
'DO YOUR CODE HERE
With ActiveSheet
For Each c In .Range("B2:B90").Cells
' problematic place If c.Value = Then
End If
Next c
End With
wbResults.Close SaveChanges:=False
Next lCount
End If
End With
On Error GoTo 0
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub
If this what you are looking for i have one idea.
Put all the Main product types in sheet1 of one workbook.
From second sheet onwards put each product sub products in one sheet. Use excel sheet formulas to multiply and add prices.
Record a macro to copy that price of sub products to sheet1.
store the source in a variable
figure out the price for the current row -add to a variable
when the source changes put the totals in a column to the right
maybe use something like
range("A2").select
dim sSource as string
dim dPrice as decimal
Dim dWeight as decimal
dim dtotal as decimal
Do Until ActiveCell = ""
sSource = ActiveCell.Offset(0,8).value
dprice = Activecell.offset(0,7).value
Activecell.Offset(1,0).Select
etc.....
when your source changes write out to a column to the right...or something like that
Loop
Sorry, no time to write out complete code for you...but trying to get you on the path...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.