View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett Don Guillett is offline
external usenet poster
 
Posts: 10,124
Default Find & Delete columns to the left stopping at column B

If Jan-2006 IS text then this should do it

Sub findjanandmove()
On Error GoTo quitit
Set mo = Cells.Find("Jan*")
mo.Value = Left(mo, 3)
mc = mo.Column - 1
If mc = 1 Then Exit Sub
MsgBox "Jan will shift to column B"
Range(Cells(1, 2), Cells(1, mc)).EntireColumn.Delete
quitit:
End Sub

--
Don Guillett
SalesAid Software

<Aria wrote in message ...
Don, I've tried the code on its own and it works. But...when I add the
rest of mine, it errors on me after quitit. It's like the first On
Error GoTo seems to conflict with On Error Resume Next. Any thoughts to
why? I'm trying to find the "Jan-2006" text field, delete the columns
to the left so "Jan-2006" is on column B. Then, I'll search for "Jan-*"
and change it to be in "mmm" format and field in the formulas for the
rest of the year.


On Error GoTo quitit
x = Cells.Find("Jan-*").Column - 1
If x = 1 Then Exit Sub
MsgBox "Jan will shift to column B"
Range(Cells(1, 2), Cells(1, x)).EntireColumn.delete
quitit:

On Error Resume Next
Cells.Find(what:="Jan-*", after:=ActiveCell, LookIn:=xlFormulas,
lookat _
:=xlPart, searchorder:=xlByRows, searchdirection:=xlNext,
MatchCase:= _
False, searchformat:=False).Activate
Cells.Find(what:="Jan", after:=ActiveCell, LookIn:=xlValues, lookat
_
:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext,
MatchCase:= _
True, searchformat:=False).Activate
Selection.NumberFormat = "mmm"
ActiveCell.FormulaR1C1 = "1/1/2006"
ActiveCell.Select
With Selection
.HorizontalAlignment = xlCenter
End With
ActiveCell.Offset(0, 1).Range("A1").Select
ActiveCell.FormulaR1C1 =
"=DATE(YEAR(RC[-1]),MONTH(RC[-1])+2,DAY(0))"
ActiveCell.Select
Selection.NumberFormat = "mmm"
With Selection
.HorizontalAlignment = xlCenter
End With
Selection.Copy
ActiveCell.Offset(0, 1).Range("A1:J1").Select
ActiveSheet.Paste

Thanks, Aria

*** Sent via Developersdex
http://www.developersdex.com ***