formulas with enbeded quotes

l_eonandr

New Member
Joined
Feb 18, 2016
Messages
24
Please help,
I am stuck trying to code to put a formula into a column of cells, the formula has enbeded quotes which seem to stop the line from running.

Cells(iRow, 2).Value = "=MID(G11,FindN(""" \ """,G11,$C$8),(CntPosLCh(G11,""" \ """)-FindN(""" \ """,G11,$C$8)+1))"
I have tried the double quotes but that doesn't work.
If I replace the formula with "test" the cells fill fine, so the first part of this line is ok. It's the quotes inside the formula that is the problem
and I have to have the quotes in the formula.

here is the Sub code the line is in;

Sub ListMyFiles(mySourcePath, IncludeSubfolders)
Set MyObject = New Scripting.FileSystemObject
Set mySource = MyObject.GetFolder(mySourcePath)

On Error Resume Next
For Each myFile In mySource.Files
iCol = 7
Cells(iRow, iCol).Value = myFile.Path
iCol = iCol - 3
Cells(iRow, iCol).Value = myFile.Name
iCol = iCol + 1
Cells(iRow, iCol).Value = myFile.Size
iCol = iCol + 1
Cells(iRow, iCol).Value = myFile.DateLastModified
Cells(iRow, 2).Value = "=MID(G11,FindN(""" \ """,G11,$C$8),(CntPosLCh(G11,""" \ """)-FindN(""" \ """,G11,$C$8)+1))"
iRow = iRow + 1

Next
If IncludeSubfolders Then
For Each mySubFolder In mySource.SubFolders
Call ListMyFiles(mySubFolder.Path, True)
Next
End If
End Sub

any help or suggestions are appreciated.
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

sericom

Well-known Member
Joined
Jan 19, 2006
Messages
915
Cells(iRow, 2).Value = "=MID(G11,FindN("" \ "",G11,$C$8),(CntPosLCh(G11,"" \ "")-FindN("" \ "",G11,$C$8)+1))"
 

l_eonandr

New Member
Joined
Feb 18, 2016
Messages
24
Re: formulas with embeded quotes

ie;
Cells(iRow, 2).Value = "=MID(G11,FindN("" \ "",G11,$C$8),(CntPosLCh(G11,"" \ "")-FindN("" \ "",G11,$C$8)+1))"

Thanks but this I have already tried your line of code and it didn't work either, I don't know why thought it should have ... that is why I tried the double quotes in the formula I posted.
I did solve the problem by replacing the embedded " with Chr(34), and it worked wonderfully, though much longer formula than I would have liked. I would still like to find out why the above method, (your code line), did not work, I think it should have. Maybe I miss typed something, or maybe it needs the & sign to tie each piece together.
Anyway thanks for the effort and reply, much appreciated.

This is the code that worked;

Cells(iRow, 2).Value = "=MID(G11,FindN(" & Chr(34) & "\" & Chr(34) & ",G11,$C$8),(CntPosLCh(G11," & Chr(34) & "\" & Chr(34) & ")-FindN(" & Chr(34) & "\" & Chr(34) & ",G11,$C$8)+1))"
 

Watch MrExcel Video

Forum statistics

Threads
1,122,576
Messages
5,596,987
Members
414,115
Latest member
SFUser

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
Top