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.
 

Some videos you may like

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,234
Office Version
  1. 365
Platform
  1. Windows
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?
 

Tweeks

Board Regular
Joined
Jul 27, 2004
Messages
52
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,234
Office Version
  1. 365
Platform
  1. Windows
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.
 

Tweeks

Board Regular
Joined
Jul 27, 2004
Messages
52

ADVERTISEMENT

It has to be in VBA code, although the '*' can be anything if that helps.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,234
Office Version
  1. 365
Platform
  1. Windows
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?
 

Tweeks

Board Regular
Joined
Jul 27, 2004
Messages
52
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.
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,234
Office Version
  1. 365
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,436
Messages
5,601,671
Members
414,466
Latest member
Jools23

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