Looping VBA with Substituting Format

Read_This

New Member
Joined
Aug 13, 2014
Messages
37
I wonder if you can help.

I'm looking for some simple VBA to allow me to loop through column A in a worksheet. If the cell in column A contains any data, then format its adjacent cell in column B.
Also, should that adjacent cell in column B 'not' have any data to format, then continue to loop through column A until the cells in column A are found empty - then stop.


The format I am looking for in column B is
=IF(A1="",TEXT(RIGHT(SUBSTITUTE($B1," ",""),10),"00000 000000"),TEXT(RIGHT(SUBSTITUTE($B1," ",""),10),"00000 000000"))



[this will format a number into a 12 digit UK telephone number that begins with a zero and has a space after the 5th digit]

Help and pointers would be appreciate.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
I think this macro will do what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub FormatColumnBifColumnAhasData()
  With Range("A1", Cells(Rows.Count, "A").End(xlUp))
    .Offset(, 1).Value = Evaluate(Replace("IF(LEN(" & .Address & "),TEXT(RIGHT(SUBSTITUTE(#,"" "",""""),10),""00000 000000""),IF(#="""","""",#))", "#", .Offset(, 1).Address))
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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