I am want to be able to take "bulk" material lists and have them automatically summarized to "sum" like-with-like items.
For example, would there be an efficient way to accomplish the following?
Is there an efficient way to get from:
To
I currently select all of the data from the first photo and do a SORT in the following order by the following:
1) Species
2) Size (W)
3) Size (H)
4) Length
5) PCS
Then I select the "Sort anything that looks like a number, as a number" option. . .
But after I do that sort, I have to manually calculate the total quantity of "like" items in order to fully summarize my list to end up with how the second photo looks like. . .
Is there something that can automatically summarize the data from Photo 1 to make it look exactly like Photo 2?
Your help will make my life a LOT easier! Thank you for your time!
Try this:
What this does is starting in row 2, checks all the other rows for a match based on Size (W), Size (H), Length and Species. If those all match, then PCS and Order are summed together and one of the rows are deleted.
Sub Consolidate()
Dim i As Long
For i = 8 To Cells(Rows.Count, 1).End(xlUp).Row
For j = Cells(Rows.Count, 1).End(xlUp).Row To 8 Step -1
If i <> j Then
If Cells(i, 6).Value = Cells(j, 6).Value And _
Cells(i, 8).Value = Cells(j, 8).Value And _
Cells(i, 9).Value = Cells(j, 9).Value And _
Cells(i, 10).Value = Cells(j, 10).Value And _
Cells(i, 11).Value = Cells(j, 11).Value Then
Cells(i, 2).Value = Cells(i, 2).Value + Cells(j, 2).Value
Rows(j).Delete
End If
End If
Next j
Next i
End Sub
Related
I have an Excel list of IPOs made in Europe from years 2000-2020 and a second list of all the loans of years 1999-2020 made in Europe. I need to find which of these IPOs from the first list received a loan from this second list of data (loan received maximum one year before the IPO). How can I do it? I wrote this code for VBA, someone can help me to adjust it please? Is there a simpler way to do it?
code:
Sub
i = 2
Do Until Cells(i, 1).Value = ""
j = 2
Cells(i, 5).Value = 0
Do Until Cells(j, 3).Value = "" Or Cells(i, 5).Value = 1
If Cells(i, 2).Value = Cells(j, 4).Value Then
If Cells(i, 1).Value > Cells(j, 3).Value And Cells(i, 1).Value < Cells(j, 3).Value And Cells(i, 1).Value > Cells(j, 3).Value - 365 Then
Cells(i, 5).Value = 1
End If
j = 1 + i
Loop
i = i + 1
Loop
End Sub
I can achieve your result w/o VBA using this formula
=IF(ISNA(VLOOKUP(B7,$F$4:$G$7,1,FALSE)),0,IF(AND((C7-(VLOOKUP(B7,$F$4:$G$7,2,FALSE))<365),(C7-(VLOOKUP(B7,$F$4:$G$7,2,FALSE))>0)),1,0))
In case you want to maintain the sequence of your column, then you have to use index-match function to replace Vlookup
I need to make Excel VBA script which inserts formula depending on cells values.
My current version returns only FALSE value
For i = 1 To 10 Step 1
If Cells(i, 2).Value > Cells(i, 1).Value Then Cells(i, 3).Value = Cells(i, 3).Formula = "=cells(i,1).value+cells(i,2).value"
If Cells(i, 2).Value < Cells(i, 1).Value Then Cells(i, 3).Value = Cells(i, 3).Formula = "=cells(i,2).value-cells(i,1).value"
Next i
I geuss you would like to do something like that
For i = 1 To 10 Step 1
If Cells(i, 2).Value > Cells(i, 1).Value Then Cells(i, 3).FormulaR1C1 = "=RC[-2]+RC[-1]"
If Cells(i, 2).Value < Cells(i, 1).Value Then Cells(i, 3).FormulaR1C1 = "=RC[-2]-RC[-1]"
Next i
First, it returns FALSE because you compare the formula of the cell with your string. Those are not equal, hence it returns FALSE. This would be solved by leaving out the =Cells(i,3).Formula part.
Second, it is important to be aware that certain VBA functionality cannot be used in your worksheet and vice versa. When you type '=Cells' in a cell you will note there is no Worksheet function called Cells. That's why the following will return '#Field!'
For i = 1 To 10 Step 1
If Cells(i, 2).Value > Cells(i, 1).Value Then
Cells(i, 3).Formula = "=cells(i,1).value+cells(i,2).value"
End if
If Cells(i, 2).Value < Cells(i, 1).Value Then
Cells(i, 3).Formula = "=cells(i,2).value-cells(i,1).value"
End if
Next i
The easiest thing to do is performing the calculation within VBA:
For i = 1 To 10 Step 1
If Cells(i, 2).Value > Cells(i, 1).Value Then
Cells(i, 3).Value = Cells(i, 1).Value + Cells(i, 2).Value
End if
If Cells(i, 2).Value < Cells(i, 1).Value Then
Cells(i, 3).Formula = Cells(i, 2).Value - Cells(i, 1).Value
End if
Next i
Some recommendations:
Instead of addressing a cell value multiple times, assign the value to a variable.
Try avoiding writing formulas to worksheets. This will slow down your code big time. If you must, then consider storing all the formulas in an array first and only write them to the worksheet when the entire array has been filled.
In this case you can avoid using VBA altogether.
Consider checking if the value of the cell is numeric before performing calculations.
If you insist on using a worksheet function, you could use Storax's suggestion.
I'm facing issue with a condition within a VBA code.
If Cells(i, 10).Value = Blank And Cells(i, 26).Value <= 61 _
And Cells(i, 1).Value <> "*30G*" Then
I would like to ignore the row which contains the following string in his cells value (col A). Basically, the Cells(I, 1).Value are ID number. The objective is to send email only for the #ID that does not contains or starting with "30G". Otherwise, the code is running well, I'm stuck with this new constraint.
If the cells.value does not contains ā30Gā Then
Use InStr function
Is this what you are trying?
If Len(Trim(Cells(i, 10).Value)) = 0 And _
Cells(i, 26).Value <= 61 And _
InStr(1, Cells(i, 1).Value, "30G", vbTextCompare) = 0 Then
End If
I have two columns, Column A has a set of a few standard values and column B has all unique values. I'm only just experimenting with more complex ways of compiling data than the beginner level so I'm a bit at a loss.
I need to either have a lookup or create a macro that will list only the values in A (once each) but also display which values in B correspond to those in A
for example
A | B
va1|abc
va1|bcd
Va2|xyz
va3|zab
will show (in a single cell) the following
va1: abc, bcd
va2: xyz
va3: zab
Please help!
Option Explicit
Sub Test()
Dim i As Long, j As Long, k As Long
k = 1
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Application.CountIf(Range("C:C"), Cells(i, 1).Value) = 0 Then
Cells(k, 3).Value = Cells(i, 1).Value
For j = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(j, 1).Value = Cells(k, 3).Value And _
InStr(Cells(k, 4).Value, Cells(j, 2).Value) = 0 Then
If Cells(k, 4).Value = "" Then
Cells(k, 4).Value = Cells(j, 2).Value
Else
Cells(k, 4).Value = Cells(k, 4).Value & ", " & Cells(j, 2).Value
End If
End If
Next j
k = k + 1
End If
Next i
For i = 1 To Cells(Rows.Count, 3).End(xlUp).Row
Cells(i, 3).Value = Cells(i, 3).Value & ": " & Cells(i, 4).Value
Cells(i, 4).ClearContents
Next i
End Sub
Edited for single cell
In case your requirement is to "have the grouped data", and not exactly "have one single string per A", you can do this with a "pivot table" putting A and B in the row labels, like in the following picture:
Hello I have the following problem:
As you can see in column A we have Dates, in column B there is always a "1" when a year changes from one to the next, I marked it in yellow. In column H are different values and in column I, I want to have only the FIRST value, which is greater (in this case) than 10% within one year (so in the period from one to one in column B). After that I want to have the next first value, which is >10% in the next year so next period from 1 to 1 in column B and so on.
Can anyone help me?
So far I programmed this, but it shows me all values >10% but not the first from each range to each range.
Sub ABC ()
With ThisWorkbook.Worksheets("Test")
rowCount = 2
Do While .Cells(rowCount + 1, 8).Value <> ""
If .Cells(rowCount, 2).Value = 0 And .Cells(rowCount, 8).Value >= 0.1 Then
.Cells(rowCount, 9).Value = .Cells(rowCount, 7).Value * 0.1 / 1.1
Else
.Cells(rowCount, 9).Value = ""
End If
rowCount = rowCount + 1
Loop
End With
End Sub
It seem the code is error on the cell address
Sub ABC ()
With ThisWorkbook.Worksheets("Test")
rowCount = 2
Do While .Cells(rowCount + 1, 8).Value <> ""
If .Cells(rowCount, 2).Value = 0 And .Cells(rowCount, 8).Value >= 0.1 Then
.Cells(rowCount, 9).Value = .Cells(rowCount, 8).Value * 0.1 / 1.1
Else
.Cells(rowCount, 9).Value = ""
End If
rowCount = rowCount + 1
Loop
End With
End Sub