Hi Cindy,
I have received your code from the macro you have recorded.
I can't tell much myself but first to define a name for your pivot table.This can be done in Excel in the formula tab "define name" then check in "Name manage" if you run 2007 or 2010 or the insert menu I think if you run 2003,tough it is still called up with "define name" or "name manager".
Then in your code, replace the field of the worksheet you want to query in the vlookup function with the name you have defined. I can see in your code :
ActiveCell.FormulaR1C1 = "=VLOOKUP(Sheet1!RC[-2],'navision '!R2C1:R8000C13,12,FALSE)"
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-13],Sheet1!R5C1:R3000C3,2,FALSE)"
The reason your code doesn't find the vlookup value is when you record it, you change worksheets, at one point you apply vlookup onto another worksheet (navision) and later on from this worksheet, you apply vlookup. Moreover, I don't know if you've ticked relative reference when you've created themacro but if it's the case, if you're moving while recording your macro, running your macro can be different... And last thing which makes things noteasy, your using column row notation, this is a good thing if you want to get into coding but at many levels "A1, B2..." notation is more simple.
So for now, I can just tell you to define a name for your pivot table anduse that same name in the vlookup: "=VLOOKUP(Sheet1!RC[-2],NEWNAME,12,FALSE)" position yourself after the "[-2]," coma and press F3, it will bring the name you have defined automatically.
Apply this to the other vlookup formula and it should be working.
HTH,
Pascal Baro
I try to record a macro, but have run into a problem: my macro
includes vlookup a pivot table. But the pivot table sheet did not
always come out the same name( in my macro, it is called " sheet2"),
so the vlooup does not know where to look, and returns error. Does
someone know how to solve this problem? Thanks a lot!- Hide quoted text -
- Show quoted text -