Excel Macro to search for specific cell and subtract value
Closed
MaxvdP
Posts
1
Registration date
Wednesday 4 June 2014
Status
Member
Last seen
4 June 2014
-
4 Jun 2014 à 05:36
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 10 Jun 2014 à 10:28
TrowaD Posts 2921 Registration date Sunday 12 September 2010 Status Contributor Last seen 27 December 2022 - 10 Jun 2014 à 10:28
Related:
- Excel Macro to search for specific cell and subtract value
- Excel mod apk for pc - Download - Spreadsheets
- How do i find a specific video on youtube - Guide
- How to search for a specific word on a webpage - Guide
- Excel online macros - Guide
- Yahoo search history - Guide
2 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
5 Jun 2014 à 11:03
5 Jun 2014 à 11:03
Hi Max,
What column do you use for your "codes" and what column for your values or are they scattered across your sheets?
Best regards,
Trowa
What column do you use for your "codes" and what column for your values or are they scattered across your sheets?
Best regards,
Trowa
Good morning Trowa,
The information is in columns. So the code (serial number) on the first sheet is in one column with the associated number (items used) in a column next to it. It's the same on the other sheet, the codes are down one column, with the number associated with it (items in stock) in a column next to it.
Thanks for any help you can give,
Max
The information is in columns. So the code (serial number) on the first sheet is in one column with the associated number (items used) in a column next to it. It's the same on the other sheet, the codes are down one column, with the number associated with it (items in stock) in a column next to it.
Thanks for any help you can give,
Max
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
10 Jun 2014 à 10:28
10 Jun 2014 à 10:28
Hi Max,
You didn't provide the specifics.
So the first sheet is named "Sheet1". The codes are in column A and the values are in column B. Row 1 used as header. Same setup for the second sheet which is called "Sheet2". The subtractions will happen on sheet1.
Here is the code:
Best regards,
Trowa
You didn't provide the specifics.
So the first sheet is named "Sheet1". The codes are in column A and the values are in column B. Row 1 used as header. Same setup for the second sheet which is called "Sheet2". The subtractions will happen on sheet1.
Here is the code:
Sub RunMe()
Dim x As Integer
Dim lRow1, lRow2 As Long
lRow1 = Sheets("Sheet1").Range("A1").End(xlDown).Row
lRow2 = Sheets("Sheet2").Range("A1").End(xlDown).Row
Sheets("Sheet2").Select
For Each cell In Range("A2:A" & lRow2)
x = 1
Do
x = x + 1
If cell.Value = Sheets("Sheet1").Cells(x, "A") Then
Sheets("Sheet1").Cells(x, "B").Value = Sheets("Sheet1").Cells(x, "B").Value - cell.Offset(0, 1).Value
End If
Loop Until x = lRow1
Next cell
End Sub
Best regards,
Trowa