View Single Post
  #14   Report Post  
Posted to microsoft.public.excel.programming
Phrank Phrank is offline
external usenet poster
 
Posts: 153
Default Rearranging columns in a large spreadsheet

Hi Claus and Garry,

I was finally able to get back to this and finish it up. The code
below works like a champ now - and fast too. There was (is?) and
issue with the way the workbook is initially compiled, and i believe a
few other lines of my code where i was inseting 4 columns at column A
contributed to the layout/formatting issue. Those other lines of code
worked well where they were placed, but after adjusting and and moving
those, all fell into place. I still insert those four columns, but
before I was inserting the columns and then moving them around with
your code. Now I run your code and then insert the four new columns
into the location where I want them. Not sure why inserting columns
up front would cause the slow down I experienced, but it did.

Garry, your code probably works well, but I had already started down
the road with this code, and with my current level and time
constraints at work, it was a lot easier for me to try and figure this
one out. As you said (and I realize), there are some things that we
will simply need better and more experienced programmers to create.

Thank you both VERY much for your time and help!

Best regards,

Frank

On Wed, 17 Jun 2015 08:26:57 +0200, Claus Busch
wrote:

Hi Frank,

Am Tue, 16 Jun 2015 22:44:49 -0400 schrieb Phrank:

I first tried changing the calculation to manual, but that had no
effect. I put the autocalc code in both the main macro and the sub
routine with the same result. Below is the code that gets run that
does indeed work, just very slow (this is part of a 'formatting'
macro, not too much else going on, but a little bit).


you don' t need strCols because your columns will go one by one.
Following code does that in a blink. If it works slow on your machine
the rest of your code causes that issue:

Sub Test()
Dim wksSource As Worksheet
Dim strHeaders As String
Dim varHeaders As Variant
Dim i As Long, c As Range

Set wksSource = Sheets("Sheet1")

Application.ScreenUpdating = False
With wksSource
strHeaders = "Age(Dynamic),ProView,INV#,CMPL#,PI#," _
& "Investigation Assigned to,Investigation State,Op Lvl," & _
"Catalog #,User Notes,System Likely Rationale,My Likely Rationale" _
& ",System Rationale for Internal Testing," & _
"My Rationale for Internal Testing,LastReviewed,Product Long Description"
varHeaders = Split(strHeaders, ",")

For i = UBound(varHeaders) To LBound(varHeaders) Step -1
Set c = Range("1:1").Find(varHeaders(i), , xlValues, xlWhole)
If Not c Is Nothing Then
.Columns(c.Column).Cut
.Columns("A").Insert Shift:=xlToRight
End If
Next
End With 'wksSource
Application.ScreenUpdating = True
End Sub


Regards
Claus B.