Excel VBA Using Variables in Left Statement

Steve001

Board Regular
Joined
Apr 13, 2017
Messages
78
Office Version
  1. 365
  2. 2021
  3. 2013
Platform
  1. Windows
Hello Gurus

Lots of posts on here about this sort of thing but cannot get them to work.

Looking at the following statement:

=LEFT(Y2,10)+SUBSTITUTE(RIGHT(Y2,12),":",".",3)

i am trying to replace 'Y2' in both instances with variables not had any luck can somebody please advise

I am using office 363 & office 2021

Regards

Steve
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You can give a couple of examples of what you have in cell Y2 and what you expect as a result.
 
Upvote 0
Hi Dante,

This post, is what i am trying to do .. pop it at the end of the columns after leaving a bit if a gap


I am trying to populate the cell with that formula, but biased on variables to position it in my sheet using cells.Formula

Regards

Steve
 
Upvote 0
The management of variables in the formula is only possible in versions of 365, 2021 onwards

Try:
Excel Formula:
=LET(a, Y2,LEFT(a,10)+SUBSTITUTE(RIGHT(a,12),":",".",3))

😇
 
Upvote 0
The management of variables in the formula is only possible in versions of 365, 2021 onwards

Try:
Excel Formula:
=LET(a, Y2,LEFT(a,10)+SUBSTITUTE(RIGHT(a,12),":",".",3))

😇
In the thread title, the OP is asking for VBA.
 
Upvote 0
In the thread title, the OP is asking for VBA.
Gud catch


I am trying to populate the cell with that formula, but biased on variables to position it in my sheet using cells.Formula

Try this.
The ini variable with the cell that contains cell Y2.
The fin variable with the cell where you want the formula.

VBA Code:
Sub UseVariable()
  Dim ini As String, fin As String
  
  ini = "Y2"
  fin = "AA2"
  Range(fin).Formula = "=LEFT(" & ini & ",10)+SUBSTITUTE(RIGHT(" & ini & ",12),"":"",""."",3)"
End Sub

🤗
 
Upvote 0
Solution

Forum statistics

Threads
1,225,749
Messages
6,186,802
Members
453,373
Latest member
Ereha

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