eoinymc

Board Regular
Joined
Jan 29, 2009
Messages
203
Hi,

I have the following formula, which works when I type it into a cell in excel:
Code:
=OFFSET(INDIRECT("'" & $AM6 & "'!$A$" & MATCH($A6,INDIRECT("'" & $AM6 & "'!$A:$A"),0)),31,1)

However, when I try to put this in VBA, I keep getting errors...I believe it's because of the double quotes and single quotes:

Code:
Tfc.Cells(6, 26)="=OFFSET(INDIRECT("'" & $AM6 & "'!$A$" & MATCH($A6,INDIRECT("'" & $AM6 & "'!$A:$A"),0)),31,1)"

I have tried to put in Chr(39) for single quotes and Chr(34) for double quotes, but it doesn't seem to work...

Anyone got any ideas as to why this won't work? Could it be because of Indirect? I think I can remember having issues with Indirect in VBA previously.

Thanks,

Eoin
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
try this:

Tfc.Cells(6, 26)="=OFFSET(INDIRECT(""'"" & $AM6 & ""'!$A$"" & MATCH($A6,INDIRECT(""'"" & $AM6 & ""'!$A:$A""),0)),31,1)"
 
Upvote 0
Do you really want the formula entered in the cell via VBA, or is the goal to get the actual result of the formula into the cell??
If you're doing this in VBA, it's just creating double work to use Indirect. You can specify the different sheets within VBA itself.

You might try something like

Code:
Dim ws As Worksheet, MyRow As Long

Set ws = SheetS(Tfc.Range("AM6").Value)
MyRow = Application.Match(Tfc.Range("A6"),ws.Range("A:A"),0)
Tfc.Cells(6,26).Value = ws.Cells(MyRow,1).Offset(31,1).Value
 
Upvote 0

Forum statistics

Threads
1,216,100
Messages
6,128,827
Members
449,470
Latest member
Subhash Chand

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top