Macro - Insert&Label Column, if the labeled column doesn't exist

  • Thread starter Thread starter Jeff
  • Start date Start date
J

Jeff

Need help creating a macro based upon certain conditions. The Excel
files I will use are in the form of a table database (i.e., first row
has column headings and rows 2 through.... have the related data).
Eventually I will link this Excel file to Microsoft Access.

Question - I would like a macro that will "Find" a particular column
heading (say "Other Sales"). If found, then the macro will end. If it
can't find "Other Sales", the macro will insert a column (location of
new column doesn't matter) and label it "Other Sales", then the macro
would end.

Any help would be appreciated
 
Hi Jeff:

Dim XLCell as Range

Set XLCell = Sheets("SheetName").Range("1:1").Find("YOUR
HEADER",,xlValues,xlWhole)
If XLCell Is Nothing Then Sheets("SheetName").Range("B1").EntireColumn.Insert
Sheets("SheetName").Range("B1").Value = ""YOUR HEADER"

- That will insert a column to the left of column B - you can adjust it as
needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top