D
davegb
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.
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.