VBA equivelent to Cell Formula ?

Asrampd

Board Regular
Joined
Feb 26, 2012
Messages
247
Can anyoe help me with some code equivalent to the following Formulas - BUT I also need to see the setting up of the variable that will hold the results and the code to place the result into a cell

=MID(A8, 2,3) , so that if the content of A8 was "L096n011_SET_Export.xls" it outputs 096 (without loosing the zero).

Ta.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Something like
Code:
Dim extractedNumeral As String

extractedNumeral = Mid(Range("A8").Text, 2, 3)
 
Upvote 0
Something like this perhaps which puts the result back in the cell.
Code:
Dim rng As Range


   Set rng = Range("A8")
   rng.NumberFormat = "@"
   rng.Value = Mid(rng.Value, 2,3)
 
Upvote 0
I can see that both do the job of getting the data out, I need to put the result into Cell B8 please (I will also copy this formula down the sheet do do the same on other rows).

Ta.
 
Upvote 0
Put the worksheet formula =MID(A8, 2, 3) in B8 and drag down.

Sometimes the best way to use Excel VBA is to use Excel's non-VBA capabilities.
 
Upvote 0
If all you want is code for putting the result in B8:
Code:
Dim rng As Range 

Set rng = Range("A8")

    With rng.Offset(0,1)
       .NumberFormat = "@"
       .Value = Mid(rng.Value,2,3)
      End With
That isn't a formula though and can't be copied down.

Do you actually want code to enter the formula down column B?
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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