LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default delete column sets current cell wrong

I have code that looks at the column headers in a sheet and in some
cases, deletes the column, in others, replaces the header with a
different one, based on a table of old header values and new header
values in a different workbook. The problem is, that as the macro goes
through the range (rTtl), when a column is deleted, it skips the column
to the deleted columns right and continues. In other words, rCell is
one cell to the right of where I want it to be after a column is
deleted. How do I "back up" rCell one cell to the left, the next
unevaluated column, after a column is deleted?

For Each rCell In rTtl
strOldHd = rCell.Value

Set rFoundHdr = rOldHds.Find(strOldHd, LookIn:=xlValues,
LookAt:=xlWhole)

If Not rFoundHdr Is Nothing Then
If rFoundHdr.Offset(0, 2).Value = "delete" Then
rCell.EntireColumn.Delete
Set rCell = rCell.Offset(0, -1) <-----OBJECT REQUIRED error

Else
rCell.Value = rFoundHdr.Offset(0, 1).Value
End If
Else
lHdrNotFoundCt = lHdrNotFoundCt + 1
End If
Next rCell

I tried to set it back using an offset, but that doesn't work, I just
get an "Object Required" error on that line.

Thanks for the help.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel graph 3 sets of data. 2 sets as lines 1 as column? AndyN Charts and Charting in Excel 2 July 11th 08 01:18 PM
Formating pre-sets are all wrong ClaireView Excel Discussion (Misc queries) 4 May 22nd 07 04:51 PM
Inesert value of column B of the current row into active cell PPL[_2_] Excel Programming 4 March 5th 06 08:13 PM
Can I get current #row or #column in cell formula? ryany Excel Discussion (Misc queries) 2 February 13th 06 11:27 AM
How do I delete both sets of duplicate data? Superpreciosa Excel Discussion (Misc queries) 1 July 24th 05 08:56 PM


All times are GMT +1. The time now is 05:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"