Substitute in VBA

Ed in Aus

Well-known Member
Joined
Jul 24, 2007
Messages
829
Hi,

I am having trouble with this section of code.

Code:
If Len(ActiveCell.Value) - Len(WorksheetFunction.Substitute(ActiveCell.Value, ".", "")) <> Len(ActiveCell.Value) Then GoTo skippy

What I want is if the active cell contains a "." then go to skippy, but the code goes to it anyway.

I am trying to get the lenght of the activecell - the length of the active cell with no "."'s in it

Can anyone help
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try:
Code:
    If Not InStr(1, ActiveCell.Value, ".", vbTextCompare) = 0 Then
        GoTo skippy
    End If

Hope this helps,

Mark

Edit: ACK! Sorry, just read the second half; shame on me. Okay, which are we trying to do, go to skippy if we find a stop/dot in the active cell, or get the active cell's length (stripped of any stops)?
 
Last edited:
Upvote 0
Thanks Guys,
just went with:

Code:
If ActiveCell.Value Like "*.*" Then GoTo skippy

little bit shorter and sweeter works like a treat reading my post I was rushing my typing a fair bit
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

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