Excel VBA - delete hidden column in mergence status

  • Thread starter Thread starter seangu
  • Start date Start date
S

seangu

I want to delete the hidden columns with following scripts

Sub Macro7()
For i = 65 To 80
temp = Chr(i) & ":" & Chr(i)
Columns(temp).Select
bTEST = Selection.EntireColumn.Hidden
If bTEST = True Then
Selection.Delete Shift:=xlToLeft
i = i - 1
End If
Next
End Sub

It can work when no mergence. But if D3:H3 cells are merged, and Colum
E is hidden, the loop goes to Columns("E:E"), the property feeds back i
still "False", in that case, the hidden column E can't be delet
correctly.

Pls help out, ^_^

seang
 
Don't use merged cells ... that's the best advice I can give you.

In this particular case, you can probably solve your problem by skipping the
Select step and using Columns(temp) instead of Selection in the next two
steps.
 
thank you!
As you said, the problem is the selection.
Right now, i have change to column(temp).delete, it's working now.
 

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