Last week, Akuini gave me an awesome script that I was able to use for one of my worksheets.
I tried to expand on this to account for another scenario I needed to cover for a different sheet in the same workbook, but unfortunately, my lack of Excel skills is knocking me down again.
When I run this, I get an error saying my subscript is out of range.
I'm not sure if I'm completely off the rails with trying to adapt that code to meet this scenario, or it just needs some adjustment.
I think I'm counting the rows on one sheet, then comparing to another sheet, and it doesn't work that way?
Basically, I want to say that if no inventory value exists on the first sheet, check the second sheet for the same item number, and replace the inventory value with the one from that sheet.
Here is the code I tried and failed to work with:
ax = item number from first sheet
xb = column for new value
xd = existing value on first sheet
xe = item number of second sheet
xf = value on second sheet
I hope I'm being clear.
Basically:
IF xd is blank or zero THEN match xe with ax and populate xb with xf.
Let me know if there are any questions, and thank you guys for all the help!
I tried to expand on this to account for another scenario I needed to cover for a different sheet in the same workbook, but unfortunately, my lack of Excel skills is knocking me down again.
When I run this, I get an error saying my subscript is out of range.
I'm not sure if I'm completely off the rails with trying to adapt that code to meet this scenario, or it just needs some adjustment.
I think I'm counting the rows on one sheet, then comparing to another sheet, and it doesn't work that way?
Basically, I want to say that if no inventory value exists on the first sheet, check the second sheet for the same item number, and replace the inventory value with the one from that sheet.
Here is the code I tried and failed to work with:
Code:
Sub Calculate2()Dim xa, xb, xc, xd, xe, xf
Dim i As Long, n As Long, m As Long
n = Range("C" & Rows.Count).End(xlUp).Row
m = Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
xa = Range("C14:C" & n)
xb = Range("AE14:AE" & n)
xc = Range("AF14:AF" & n)
xd = Range("Y14:Y" & n)
xe = Sheets("Sheet1").Range("A11:A" & m)
xf = Sheets("Sheet1").Range("K11:K" & m)
For i = UBound(xe, 1) - 1 To 1 Step -1
If xa(i, 1) = xe(i, 1) And xd(i, 1) < 1 Then xb(i, 1) = xf(i + 1, 1)
Next
Range("C14:C" & n) = xa
Range("AE14:AE" & n) = xb
Range("AF14:AF" & n) = xc
Range("Y14:Y" & n) = xd
Range("Sheet1.A11:A" & m) = xe
Range("Sheet1.K11:K" & m) = xf
End Sub
ax = item number from first sheet
xb = column for new value
xd = existing value on first sheet
xe = item number of second sheet
xf = value on second sheet
I hope I'm being clear.
Basically:
IF xd is blank or zero THEN match xe with ax and populate xb with xf.
Let me know if there are any questions, and thank you guys for all the help!
Last edited: