Ps. If you don't want to see the screen flickering around, you can use
something like:
Option Explicit
Sub ConvertAdwords3()
Dim myFileName As Variant
Dim CSVWks As Worksheet
myFileName = Application.GetOpenFilename(filefilter:="CSV Files, *.CSV", _
Title:="Pick a File")
If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If
Application.screenupdating = false
Set CSVWks = Workbooks.Open(Filename:=myFileName).Worksheets(1)
With CSVWks
.Rows("1:5").Delete
.Columns("J:J").Cut
.Columns("E:E").Insert Shift:=xlToRight
.Columns("K:K").Cut
.Columns("F:F").Insert Shift:=xlToRight
.Columns("K:K").Delete Shift:=xlToLeft
.Columns("L:L").Delete Shift:=xlToLeft
.Cells(.Rows.Count, "A").End(xlUp).EntireRow.Delete
End With
Application.screenupdating = True
End Sub
Dave Peterson wrote:
And some of the things that you recorded don't really help the code. Try this
against a copy of your .csv file (just in case I screwed something up):
Option Explicit
Sub ConvertAdwords2()
'
' ConvertAdwords Macro
' Macro recorded 10/4/2007 by This macro converts a
' Google AdWords report into a working Microsoft Adcenter file (Follow this
' URL to create the Google Report
' http://forums.microsoft.com/AdCenter...5020&SiteID=44)
'
' Delete Rows 1-5
'
' Rearrange columns...
' Cut, column J "Current Maximum CPC" Insert into column E
' Cut, column K " Keyword Destination URL" Insert into column F
' Delete Column K (Column L "Destination URL" becomes column K)
' Delete Column L
Rows("1:5").Delete
Columns("J:J").Cut
Columns("E:E").Insert Shift:=xlToRight
Columns("K:K").Cut
Columns("F:F").Insert Shift:=xlToRight
Columns("K:K").Delete Shift:=xlToLeft
Columns("L:L").Delete Shift:=xlToLeft
' Delete the very last row
With ActiveSheet
.Cells(.Rows.Count, "A").End(xlUp).EntireRow.Delete
End With
End Sub
And you may want to try this...
Open your macro workbook.
View|toolbars|Forms
Click on the button icon and draw a button on your worksheet
Assign your macro to that button
Change the caption to something like:
Click to Import Google AdWords CSV file
(add a few instructions to this worksheet -- or a different worksheet)
Actually, copy this code into your workbook's project and assign it to that
button.
Option Explicit
Sub ConvertAdwords3()
Dim myFileName As Variant
Dim CSVWks As Worksheet
myFileName = Application.GetOpenFilename(filefilter:="CSV Files, *.CSV", _
Title:="Pick a File")
If myFileName = False Then
MsgBox "Ok, try later" 'user hit cancel
Exit Sub
End If
Set CSVWks = Workbooks.Open(Filename:=myFileName).Worksheets(1)
With CSVWks
.Rows("1:5").Delete
.Columns("J:J").Cut
.Columns("E:E").Insert Shift:=xlToRight
.Columns("K:K").Cut
.Columns("F:F").Insert Shift:=xlToRight
.Columns("K:K").Delete Shift:=xlToLeft
.Columns("L:L").Delete Shift:=xlToLeft
.Cells(.Rows.Count, "A").End(xlUp).EntireRow.Delete
End With
End Sub
You'll be prompted for what .csv file to open.
ZenMasta wrote:
Oh, here's the code. Hopefully someone will find it via search engine one of
these days.
Sub ConvertAdwords()
'
' ConvertAdwords Macro
' Macro recorded 10/4/2007 by This macro converts a
Google AdWords report into a working Microsoft Adcenter file (Follow this
URL to create the Google Report
http://forums.microsoft.com/AdCenter...5020&SiteID=44)
'
' Delete Rows 1-5
'
' Rearrange columns...
' Cut, column J "Current Maximum CPC" Insert into column E
' Cut, column K " Keyword Destination URL" Insert into column F
' Delete Column K (Column L "Destination URL" becomes column K)
' Delete Column L
'
Application.WindowState = xlNormal
Application.Left = 10
Application.Top = 35.5
Application.Width = 767.25
Application.Height = 585
Rows("1:5").Select
Selection.Delete Shift:=xlUp
Columns("J:J").Select
Selection.Cut
Columns("E:E").Select
Selection.Insert Shift:=xlToRight
Columns("K:K").Select
Selection.Cut
Columns("F:F").Select
Selection.Insert Shift:=xlToRight
Columns("K:K").Select
Selection.Delete Shift:=xlToLeft
Columns("L:L").Select
Selection.Delete Shift:=xlToLeft
' Delete the very last row
With ActiveSheet
.Cells(.Rows.Count, "A").End(xlUp).EntireRow.Delete
End With
End Sub
--
Dave Peterson
--
Dave Peterson