SydneyLucy
New Member
- Joined
- Sep 12, 2010
- Messages
- 4
I have an excel sheet with columns of data that then needs to be transposed into rows, however each column is a different length and there are loads of columns so to do each one individually takes too long. I have managed to get the keywords over and walking through the macro it brings the top 2 titles over but the pulls down the wrong data.
Original columns look like this, with various numbers of keywords
campaign1
adgroup1
keyword1
keyword2
keyword3
keyword4
keyword5
this needs to move to the spreadsheet to look like this
campaign1 adgroup1 keyword1
campaign1 adgroup1 keyword2
campaign1 adgroup1 keyword3 etc
This is the macro I'm using. Any help really appreciated!
Sub Keyword_Transform()
Dim lngInputColumnID As Long, lngOutputRow As Long
Dim wksSource As Worksheet, wksdest As Worksheet
Dim lngColNo As Long
Dim strTemp As String
Set wksSource = Worksheets("Campaign Structure")
Set wksdest = Worksheets("DS_Kwds")
Application.ScreenUpdating = False
' Delete existing content
wksdest.Range("A7:Z7", wksdest.Range("A7:Z7").End(xlDown)).ClearContents
lngOutputRow = 7
For lngInputColumnID = 2 To 256
Application.StatusBar = "Processing column " & lngInputColumnID - 1 & " of 255"
'see if there's an Ad group title & at least 1 keyword
If wksSource.Cells(10, lngInputColumnID).Value <> "" Then
If wksSource.Cells(71, lngInputColumnID).Value <> "" Then
'wksSource.Cells(10, lngInputColumnID).Copy
wksdest.Cells(lngOutputRow, 17).Value = wksSource.Cells(10, lngInputColumnID).Value 'Campaign
wksdest.Cells(lngOutputRow, 16).Value = wksSource.Cells(70, lngInputColumnID).Value 'Ad group
strTemp = wksSource.Cells(68, lngInputColumnID).Value 'cost per click
strTemp = Application.WorksheetFunction.Substitute(strTemp, "$", "") 'remove dollar signs ($)
wksdest.Cells(lngOutputRow, 9).Value = strTemp 'PasteSpecial xlPasteValues
wksdest.Cells(lngOutputRow, 10).Value = strTemp 'PasteSpecial xlPasteValues
wksdest.Cells(lngOutputRow, 5).Value = wksSource.Cells(65, lngInputColumnID).Value 'Link URL
'Keywords
If wksSource.Cells(71, lngInputColumnID).Offset(1, 0) = "" Then
wksSource.Cells(71, lngInputColumnID).Copy
Else
wksSource.Range(wksSource.Cells(71, lngInputColumnID), wksSource.Cells(71, lngInputColumnID).End(xlDown)).Copy
End If
wksdest.Cells(lngOutputRow, 2).PasteSpecial xlPasteValues
'Engine-specific data
Select Case wksSource.Range("Engine").Value
Case "Yahoo"
wksdest.Cells(lngOutputRow, 3).Value = "Advanced" 'Match type
wksdest.Cells(lngOutputRow, 8).Value = 0.1 'Min bid
Case "Google"
wksdest.Cells(lngOutputRow, 3).Value = "Broad" 'Match type
wksdest.Cells(lngOutputRow, 8).Value = 0.01 'Min bid
End Select
If wksdest.Cells(lngOutputRow, 2).Offset(1, 0).Value = "" Then
lngOutputRow = lngOutputRow + 1
Else
With wksdest.Cells(lngOutputRow, 2).End(xlDown).Offset(0, 1)
wksdest.Range(.Cells, .End(xlUp)).FillDown
'lngOutputRow = .Offset(1).Row
End With
With wksdest.Cells(lngOutputRow, 2).End(xlDown).Offset(0, 3).Range("A1:m1")
wksdest.Range(.Cells, .End(xlUp)).FillDown
lngOutputRow = .Offset(1).Row
End With
End If
End If
End If
Next lngInputColumnID
wksdest.Select
wksdest.Range("A6").Select
' wksSource.Select
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub
Original columns look like this, with various numbers of keywords
campaign1
adgroup1
keyword1
keyword2
keyword3
keyword4
keyword5
this needs to move to the spreadsheet to look like this
campaign1 adgroup1 keyword1
campaign1 adgroup1 keyword2
campaign1 adgroup1 keyword3 etc
This is the macro I'm using. Any help really appreciated!
Sub Keyword_Transform()
Dim lngInputColumnID As Long, lngOutputRow As Long
Dim wksSource As Worksheet, wksdest As Worksheet
Dim lngColNo As Long
Dim strTemp As String
Set wksSource = Worksheets("Campaign Structure")
Set wksdest = Worksheets("DS_Kwds")
Application.ScreenUpdating = False
' Delete existing content
wksdest.Range("A7:Z7", wksdest.Range("A7:Z7").End(xlDown)).ClearContents
lngOutputRow = 7
For lngInputColumnID = 2 To 256
Application.StatusBar = "Processing column " & lngInputColumnID - 1 & " of 255"
'see if there's an Ad group title & at least 1 keyword
If wksSource.Cells(10, lngInputColumnID).Value <> "" Then
If wksSource.Cells(71, lngInputColumnID).Value <> "" Then
'wksSource.Cells(10, lngInputColumnID).Copy
wksdest.Cells(lngOutputRow, 17).Value = wksSource.Cells(10, lngInputColumnID).Value 'Campaign
wksdest.Cells(lngOutputRow, 16).Value = wksSource.Cells(70, lngInputColumnID).Value 'Ad group
strTemp = wksSource.Cells(68, lngInputColumnID).Value 'cost per click
strTemp = Application.WorksheetFunction.Substitute(strTemp, "$", "") 'remove dollar signs ($)
wksdest.Cells(lngOutputRow, 9).Value = strTemp 'PasteSpecial xlPasteValues
wksdest.Cells(lngOutputRow, 10).Value = strTemp 'PasteSpecial xlPasteValues
wksdest.Cells(lngOutputRow, 5).Value = wksSource.Cells(65, lngInputColumnID).Value 'Link URL
'Keywords
If wksSource.Cells(71, lngInputColumnID).Offset(1, 0) = "" Then
wksSource.Cells(71, lngInputColumnID).Copy
Else
wksSource.Range(wksSource.Cells(71, lngInputColumnID), wksSource.Cells(71, lngInputColumnID).End(xlDown)).Copy
End If
wksdest.Cells(lngOutputRow, 2).PasteSpecial xlPasteValues
'Engine-specific data
Select Case wksSource.Range("Engine").Value
Case "Yahoo"
wksdest.Cells(lngOutputRow, 3).Value = "Advanced" 'Match type
wksdest.Cells(lngOutputRow, 8).Value = 0.1 'Min bid
Case "Google"
wksdest.Cells(lngOutputRow, 3).Value = "Broad" 'Match type
wksdest.Cells(lngOutputRow, 8).Value = 0.01 'Min bid
End Select
If wksdest.Cells(lngOutputRow, 2).Offset(1, 0).Value = "" Then
lngOutputRow = lngOutputRow + 1
Else
With wksdest.Cells(lngOutputRow, 2).End(xlDown).Offset(0, 1)
wksdest.Range(.Cells, .End(xlUp)).FillDown
'lngOutputRow = .Offset(1).Row
End With
With wksdest.Cells(lngOutputRow, 2).End(xlDown).Offset(0, 3).Range("A1:m1")
wksdest.Range(.Cells, .End(xlUp)).FillDown
lngOutputRow = .Offset(1).Row
End With
End If
End If
End If
Next lngInputColumnID
wksdest.Select
wksdest.Range("A6").Select
' wksSource.Select
Application.ScreenUpdating = True
Application.StatusBar = False
End Sub