Excel Macro Question

Mooslar

New Member
Joined
Oct 3, 2017
Messages
1
Hello everybody,

I did some digging around the forum and couldn't find anything pertaining to my question. I have a macro that performs a huge of amount of maintenance on a particular file. However, because nothing is easy, the one of the worksheets will be missing a certain column under certain conditions. This causes the macro to fail. The only change I need to make to correct the problem is to insert a 'dummy' column in its place.

Is there a way I can have the macro read a certain cells value, and depending on whether or not a particular value is present, insert another column? I've tried creating if/else statements but with no luck.

Thanks.
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Mooslar,

Welcome to the Board.

You might consider...

Code:
If Range("D1").Value <> "YourValue" Then Range("D1").EntireColumn.Insert

Of course, change the ranges to your particular range.

Cheers,

tonyyy
 
Upvote 0
try this,

Code:
Sub do_it()
If Range("G1") = "" Then Columns(10).Insert Shift:=xlToRight
End Sub

it will insert a new column in column 10 if cell G1 is blank.
change column and cell reference as needed.

hth,

Ross
 
Upvote 0
Something like this:

Code:
If Range("A2")=1 and Range("B2")=1 Then Range("D1").EntireColumn.Insert Shift:=xlShiftToRight

This checks value in A2 and B2 and inserts a column in place of column, shifting columns to the right.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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