creating a Left Function using a macro

  • Thread starter Thread starter Legacy 93538
  • Start date Start date
L

Legacy 93538

Guest
Hi

I need to create a Left forumla which is created within a macro and placed in cell I2 and autofilled to the variable number z + 1.

The left forumla needs to add together the value in cell J2 and the value K2. However i need to cut the value in J2 so the result is only 7 characters long.

I think its should look like the following but I think this take the character off the end of the string instead of the first.
Code:
PPCWBSht.Range("J2").forumla = "=Left(J2 & K2,7)"

Can anyone help me? :confused:

Thanks

Jessicaseymour[:)]
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi

I may have have got a little confused as to your requirements, however does this help.

Code:
' option 1 Alpha Chars

Sheets("sheet1").Range("b2").Formula = "=Left(concatenate(J2 , K2),7)"

'option 2 Numeric Chars

Sheets("sheet1").Range("b3").Formula = "=Left(sum(J3 + K3),7)"

regards
 
Upvote 0
Jessica

Do you only want the first 7 characters of the result of joining the 2 strings?

If you do the code/formula you posted should do that.

If you don't can you explain what you do want, perhaps with some examples.
 
Upvote 0
Hi

Sorry if i didn't explain very well, i am not very good and explaning.

What it is, is that i have one workbook with two columns, J and K. The J column has AAAA in all the rows and the K column has a list starting at A.1 and ending at A.1035.

In the I column i need a forumla which adds together the values in the two columns but whenever the charatcter is more than 7 characters it removes the first chacater of the J column value.

Does that help?

Thanks for replying by the way!!:biggrin:
 
Upvote 0
Code:
"=Left(J2,7) & K2"

If I read your question correctly you want the first 7 characters of J2 plus K2?
 
Upvote 0
Code:
=IF(LEN(J2)>7,Left(J2,7) & K2, J2 & K2)

If you want the last seven characters change Left to Right
 
Upvote 0
Hi

Thanks for everyones assistance.

Code:
"=Left(J2,7) & K2"

This works very well

Thank you sooo much for your help!!!

Thanks

Jeskit
 
Upvote 0
Use this If statement, you might get an error if the Cell contains a string less than seven characters long
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,853
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