RE: Delete Column by urkec
urkec
Thu Mar 01 12:45:03 CST 2007
You can try it like this with VBScript
xlWhole = 1
xlValues = -4163
set XL = CreateObject ("Excel.Application")
XL.Visible = true
set book = XL.Workbooks.Open _
("C:\MyBook.xls")
strToFind = InputBox _
("Enter the text to find")
set rng = book.Sheets (1).UsedRange
set target = rng.Find _
(strToFind,,xlValues,xlWhole,,,true)
if not target is nothing then
rng.Columns (target.Column).Delete
else
WScript.Echo "Not found"
end if
If you want to use an Excel macro you don't need the first part of the code
Sub DeleteColumn()
strToFind = InputBox("Enter the text to find")
Set Rng = Sheets(1).UsedRange
Set target = Rng.Find _
(strToFind, , xlValues, xlWhole, , , True)
If Not target Is Nothing Then
Rng.Columns(target.Column).Delete
Else
MsgBox "Not found"
End If
End Sub
You can also add code to check if multiple cells contain the input value
(with Do..Loop and Rng.FindNext)
--
urkec
"Bernie" wrote:
> In Excel, I need a macro that will delete a column based on a cell
> that will contain a name based on an input box.
>
> Thanks,
> Bernie
>
>