Excel Macro to search for specific cell and subtract value
Closed
MaxvdP
Posts
1
Registration date
Wednesday June 4, 2014
Status
Member
Last seen
June 4, 2014
-
Jun 4, 2014 at 05:36 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 10, 2014 at 10:28 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 10, 2014 at 10:28 AM
Related:
- Excel Macro to search for specific cell and subtract value
- How to search for a specific word on a webpage - Guide
- Excel apk for pc - Download - Spreadsheets
- Spell number in excel without macro - Guide
- Yahoo search history - Guide
- Excel macro to create new sheet based on value in cells - Guide
2 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Jun 5, 2014 at 11:03 AM
Jun 5, 2014 at 11:03 AM
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 September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Jun 10, 2014 at 10:28 AM
Jun 10, 2014 at 10:28 AM
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