Translating a forumla into Code

Tweeks

Board Regular
Joined
Jul 27, 2004
Messages
52
Hi there,

I need to translate this formula:
=LEFT(C5,FIND("*",C5,1)-1)
into VBA code where the C5 is 'activecell.value'.

I think its all generally the same bar the FIND which i am not sure what it should be.

Using XL 97.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
What's the formula actually meant to do?

When you say you want to translate it what do you mean?

Do you want this formula in the active cell or do you want the VBA equivalent?
 
Upvote 0
I want to take a value from a cell that will be

number*number

So like 1*8 or 10*12

I want to store the first number into a variable, and then the other one into another variable. I need to repeat this lots of times so ideally not doing it as a formula in a spreadsheet. I can make it work in a spreadsheet ok but I would really like to be able to do this in VBA code instead. There are reasons but they are far too boring and long winded to go into here.
 
Upvote 0
Do you just want to seperate these 2 numbers into seperate cells?

If you do why not use Data>Text to Columns... with * as a delimiter.

In VBA you will have problems as the function for finding text regards * as a wildcard.
 
Upvote 0
Could you please give more details of what you are doing?

You give an example using * then say that could be anything.

Are you just trying to extract 2 numbers?
 
Upvote 0
It is really so long winded to explain.

I need to use the two numbers to loop through, so 1*8 i need to go from 1 through to 8 in some code i guess is the simplest way to explain it.
 
Upvote 0
I'm sorry but I really can't help without further explanation.

Code:
For x = Left(ActiveCell.Text, InStr(ActiveCell.Text, "*") - 1) To Mid(ActiveCell.Text, InStr(ActiveCell.Text, "*") + 1)
        MsgBox x
Next x
 
Upvote 0

Forum statistics

Threads
1,213,495
Messages
6,113,992
Members
448,538
Latest member
alex78

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