If then statement failing

icy8s1121

New Member
Joined
Oct 23, 2019
Messages
1
Hello all,

I'm having an issue getting an IF then statement to work within VBA. I'm trying to have my spreadsheet format a text to columns if A2 is blank. (meaning if it hasn't been text to columns already)

I've tried a number of different formulas. It's not skipping if A2 has data and redoing the text to columns.


Here's the formula I've been trying. I've even tried the IsEmpty formula with no luck.


If B2 = "" Then


Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(10, 1), Array(28, 1), Array(47, 1), Array(56, 1), _
Array(76, 1), Array(104, 1)), TrailingMinusNumbers:=True



End If



Any help would be greatly appreciated.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi & welcome to MrExcel.
How about
Code:
If Range("B2") = "" Then
 
Upvote 0
The code does not know what B2 is, it is looking for a variable with that name. You need to tell it to look at the range B2:

Code:
If ActiveSheet.Range("B2") = "" Then
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

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