ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   I dont understand why this happens (https://www.excelbanter.com/excel-programming/379937-re-i-dont-understand-why-happens.html)

Cooper, Scott A.

I dont understand why this happens
 
I want to cut column 2, the variable is holding the value 2 but the column 3
is the one selected. This problem is unpredictiable because the selected
column can be different. What is happening here and how do I fix it?

--
Scott A. Cooper


"Cooper, Scott A." wrote:

In the following code, columns are correctly identified with debug.print but
the wrong columns are selected when the Find function is embedded like the
second block of code. Can someone explain what is going on here?

' Code Block 1:
Debug.Print .Find("Part Number").Column
Debug.Print .Find("Product").Column
Debug.Print .Find("Cat").Column
Debug.Print .Find("Ext Qty").Column
Debug.Print .Find("List Price").Column
Debug.Print .Find("Service Months").Column

' Code Block 2:
.Columns(.Find("Part Number").Column).Cut
oNewWrk.Columns(1).Insert
.Columns(.Find("Product").Column).Cut
oNewWrk.Columns(2).Insert
.Columns(.Find("Cat").Column).Cut
oNewWrk.Columns(3).Insert
.Columns(.Find("Ext Qty").Column).Cut
oNewWrk.Columns(4).Insert
.Columns(.Find("List Price").Column).Cut
oNewWrk.Columns(5).Insert
.Columns(.Find("Service Months").Column).Cut
oNewWrk.Columns(6).Insert

--
Scott A. Cooper



All times are GMT +1. The time now is 02:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com