Open External workbook insert column problem - Stumped

R

Richard

I posted this a couple of days ago but it has still stumped me. I'm
trying to open an external workbook, select a sheet and select a
column in order to insert a new column.

My problem is that instead of selecting column F, it selects
some whole Columns "B:K". The problem is on the

With Sht

..colums("F:F".Select

line

Instead of just selecting column F, it selects the range B:K. It does
exactly the same thing whether I use the Columns("F"), or Columns(6)
syntax.

Here is what I am using:-

Set wkb = Workbooks..Open(strWorkbook)

wkb.activate

set sht = wkb("MySheet")

With sht

.activate

.columns("F:F").select ' problem seems to be here.
.columns.Insert xlToRight

Set rng = .range("F5:F15").select

For each cell in rng
cell.select
cell.value = 0
Next cell

End With

As I step through the code (from a module in another workbook) it
doesn't do what it says on the tin.

Richard





Its a good job Einstein never had to fill out one of these Government Grant applications or we never would have found out what e equalled. The West Wing
 
F

fred

Richard,
I suspect you have some merged cells ranging across columns B:K. If that is
so then the problem is that you actually select the column before inserting
your new column. Try avoiding using the Select. So try

..Range("F1").EntireColumn.Insert xlToRight


Fred


Richard said:
I posted this a couple of days ago but it has still stumped me. I'm
trying to open an external workbook, select a sheet and select a
column in order to insert a new column.

My problem is that instead of selecting column F, it selects
some whole Columns "B:K". The problem is on the

With Sht

.colums("F:F".Select

line

Instead of just selecting column F, it selects the range B:K. It does
exactly the same thing whether I use the Columns("F"), or Columns(6)
syntax.

Here is what I am using:-

Set wkb = Workbooks..Open(strWorkbook)

wkb.activate

set sht = wkb("MySheet")

With sht

.activate

.columns("F:F").select ' problem seems to be here.
.columns.Insert xlToRight

Set rng = .range("F5:F15").select

For each cell in rng
cell.select
cell.value = 0
Next cell

End With

As I step through the code (from a module in another workbook) it
doesn't do what it says on the tin.

Richard





Its a good job Einstein never had to fill out one of these Government
Grant applications or we never would have found out what e equalled. The
West Wing
 

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

Top