View Single Post
 
Old 06-12-2014, 07:11 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

I'll start looking at this, posting comments as I go. On that first section, I see you're deleting columns E, G and J. Here's how I figure that:
Code:
  Range("E:E,G:G").Select           'selects columns E and G
  Range("G1").Activate              'doesn't do anything, from your point of view
  Selection.Delete Shift:=xlToLeft  'deletes the two selected columns
  Columns("H:H").Select             'selects the new column H (was J)
  Selection.Delete Shift:=xlToLeft  'deletes the selected column
The code says to delete column H, but before you deleted E and G that column was J, right? You can accomplish all that by just one statement:
Code:
Range("E:E,G:G,J:J").Delete Shift:=xlToLeft
This is no way a complaint about your skills; you said at the start that you'd never done this before. It's just that the VBA macro recorder writes down every single action—and when you're doing it manually, you necessarily use (and it records) keystrokes that aren't necessary in the program. For example, there's no need, in the program, to select the cells and then delete them.

Now let's take a look at the next section....
Reply With Quote