Help With code to name file PLEASE

Mister H

Well-known Member
Joined
Mar 6, 2002
Messages
1,507
Hi:

I am trying to alter a code so it names the file the way the user requires it. I can not seem to get it right. I want the code to take the cvalue in C2 of the active sheet and trim the last 10 characters off it. How do i do that? I got it to do it in a cell but unfortunately I can not get it to work in VBA. No error it just does not trim off the 10 characters. Here is the formula:
=LEFT(C2, LEN(C2) - 10)

Here is the line of code I tried to put it in:
Code:
TempFileName = FilePath & Format(ActiveSheet.Range("C1"), "yyyy mm dd") & " " & "MOHLTCK" & " " [COLOR=red][B]& Format(ActiveSheet.Range("C2"), "=Left(C2, Len(C2) - 10)")[/B][/COLOR] & " " & "REV"

Any assistance as ALWAYS is GREATLY Appreciated :biggrin:

THANKS,
Mark
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi Mark. You have an unnecesserary =

Code:
TempFileName = FilePath & Format(ActiveSheet.Range("C1"), "yyyy mm dd") & " " & "MOHLTCK" & " " & Format(ActiveSheet.Range("C2"), "Left(C2, Len(C2) - 10)") & " " & "REV"
 
Upvote 0
Try:

... & LEFT(Range("C2"),LEN(Range("C2"))-10) & ...
 
Upvote 0
THANKS to both of you for your replies.

Peter: I had tried removing the = sign but it still would not trim it. Maybe it has something to do with the fact that itC2 is a merged cell. :confused:
I actually just noticed that or i would have mentioned it before. :)

Joe4: Your suggestions seems to be doing the trick. :biggrin:

THANKS agin to BOTH of you for your expertise.

Have a GREAT day,
Mark :)
 
Upvote 0
Merged cells are the work of the :diablo:

If you are going to use VBA, Center Across Selection is preferable.
 
Upvote 0
THANKS Peter... I have been learning that over the years. I try not to use them when I can get by without it. Unfortunately I am not able to alter the spreadsheet as it belongs to someone else. Is Excel 2010 still confused by Merged Cells?

THANKS,
Mark
 
Upvote 0
In Excel 2010 it is still Excel programmers that have problems with merged cells.
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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