1
votes

I would like to have a VBA code run on one, or more, specific worksheets of a workbook in Excel. But I do not wish to activate the worksheets where the code will run, I wish to have it done in the background and have the results shown on the current worksheet, where there will be a button do call the code. All the responses I have seen to such question require visiting the worksheet where the macro will run but I would like to avoid that. Perhaps putting the code inside a With statement will do the job? I have investigated it but cannot figure out all the dots in front of the lines. I tried to post the code here but I keep getting indentation errors so I will omit it for now.

Thanks in advance.

3
It would be worth posting the code - even with indentation errors. Someone else will edit it if you're not able to do it to fix the indents etc.Greg the Incredulous
you can turn off screenupdating and the macro will run in the backgroundSivaprasath Vadivel

3 Answers

3
votes

You should be able to access any worksheet and any cell in any worksheet in the workbook through VBA.

val = ActiveWorkbook.worksheets("Sheet2").cells(row, col).Value
2
votes

You can try this:

dim x as variant    
set x = sheets("Sheet1")

Just change the sheet name based on what you have.

0
votes

Thanks guys! I ended up activating every sheet (was in a hurry). Best regards,