Sub HST_move_columns()'
' HST_move_columns Macro
'
'
Sheets("Sheet1").Activate
finalrow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
finalrow2 = Sheets("Promo").Cells(Rows.Count, 1).End(xlUp).Row
finalcol = Cells(1, Columns.Count).End(xlToLeft).Column
colnum = 1
rownum = 1
colnum2 = 1
'Find header that says Promo Code and then make header in Summary tab "Customer" as we will be converting the promo code to the customer's name
'And filling that in under this header
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "Promo Code" Then
pcode = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Cells(1, colnum2) = "Customer"
Application.CutCopyMode = False
Exit For
End If
colnum = colnum + 1
Next counter
'Convert and replace promo code with full customer name
counter = 1
colnum = 1
rownum = 2
For counter = counter To finalrow
pcode = Sheets("Promo").Cells(rownum, colnum)
If pcode = "" Then
Sheets("Sheet1").Rows(rownum).Delete
Shift = xlShiftUp
Else
Custname = Application.WorksheetFunction.VLookup(pcode, Sheets("Promo").Range(Sheets("Promo").Cells(2, 1), Sheets("Promo").Cells(finalrow2, 2)), 2, False)
On Error Resume Next
Sheets("Summary").Cells(rownum, colnum) = Custname
End If
rownum = rownum + 1
Next counter
counter = 1
colnum = 1
colnum2 = colnum2 + 1
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "First Name" Then
Regdate = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Application.CutCopyMode = False
End If
colnum = colnum + 1
Next counter
counter = 1
colnum = 1
colnum2 = colnum2 + 1
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "Last Name" Then
Regdate = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Application.CutCopyMode = False
End If
colnum = colnum + 1
Next counter
counter = 1
colnum = 1
colnum2 = colnum2 + 1
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "Department:" Then
Regdate = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Application.CutCopyMode = False
End If
colnum = colnum + 1
Next counter
counter = 1
colnum = 1
colnum2 = colnum2 + 1
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "Course" Then
Regdate = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Application.CutCopyMode = False
End If
colnum = colnum + 1
Next counter
counter = 1
colnum = 1
colnum2 = colnum2 + 1
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "Course Date" Then
Regdate = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Application.CutCopyMode = False
End If
colnum = colnum + 1
Next counter
counter = 1
colnum = 1
colnum2 = colnum2 + 1
For counter = counter To finalcol
If Sheets("Sheet1").Cells(1, colnum) = "Promo Code" Then
Regdate = Sheets("Sheet1").Range(Cells(1, colnum), Cells(finalrow, colnum)).Copy
Sheets("Summary").Cells(1, colnum2).PasteSpecial Paste:=xlPasteValues
Sheets("Summary").Application.CutCopyMode = False
End If
colnum = colnum + 1
Next counter
'Enter "Amount Paid" header in farthest right empty top row cell
Sheets("Summary").Activate
rownum2 = 2
finalcol2 = Sheets("Summary").Cells(1, Columns.Count).End(xlToLeft).Column
Sheets("Summary").Cells(1, finalcol2 + 1) = "Amount Paid"
finalcol2 = Sheets("Summary").Cells(1, Columns.Count).End(xlToLeft).Column
finalcol = Cells(1, Columns.Count).End(xlToLeft).Column
counter = 1
colnumpc = 1
rownumpc = 2
For counter = counter To finalcol
If Sheets("Summary").Cells(1, colnumpc) = "Promo Code" Then
PC = Cells(rownumpc, colnumpc)
Exit For
End If
colnumpc = colnumpc + 1
Next counter
finalcol = Cells(1, Columns.Count).End(xlToLeft).Column
counter = 1
colnumco2 = 1
rownumco2 = 2
For counter = counter To finalcol
If Sheets("Summary").Cells(1, colnumco2) = "Course" Then
Co2 = Cells(rownumco2, colnumco2)
Exit For
End If
colnumco2 = colnumco2 + 1
Next counter
finalcol = Cells(1, Columns.Count).End(xlToLeft).Column
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
counter = 1
colnum = 1
rownum = 2
'Determine amount paid per student using just-moved data in Summary tab
counter2 = 1
For counter2 = counter2 To finalrow
For counter = counter To finalcol
If Sheets("Summary").Cells(1, colnum) = "Amount Paid" Then 'And Not IsEmpty(Cells(rownumpc, colnumpc)) Then
amountpaid = Sheets("Promo").Application.WorksheetFunction.VLookup(PC, Sheets("Promo").Range("table2"), WorksheetFunction.Match(Co2, Sheets("Promo").Range("bk"), 0), False)
Sheets("Summary").Cells(rownum, colnum) = amountpaid
Exit For
End If
colnum = colnum + 1
Next counter
rownumpc = rownumpc + 1
rownumco2 = rownumco2 + 1
PC = Sheets("Summary").Cells(rownumpc, colnumpc)
Co2 = Sheets("Summary").Cells(rownumco2, colnumco2)
rownum = rownum + 1
Next counter2
'
End Sub
[code/]