trevortownsend
New Member
- Joined
- Feb 11, 2019
- Messages
- 4
Hi all,
Obligatory "new to VBA"...
I'm trying to create a macro for my boss that would allow him to
1) Add a column to the far right of a table in any workbook
2) Name that column "Day of the week"
3) Find a column in the table with the header "Adj Order Date" and apply a formula in the column created in step 1 that changes the date from (ex: 2/19/2019) to (ex: Tuesday)
4) Refresh the workbook (so that the pivot linked to that table receives the new field titled "Day of the Week")
Rules:
Requirement 1 needs to be variable since he might be adding columns to the table at some point so it won't always be A:G for example.
Requirement 3 needs to be variable since "Adj Order Date" may not always be A1
Current Progress:
I'm pretty much stuck after step 1. Any help would be greatly GREATLY appreciated!
Example header and first row from the table1 referenced above:
[TABLE="width: 964"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]Adj Order Date[/TD]
[TD]Adj Fiscal Quarter[/TD]
[TD]Fiscal Quarter[/TD]
[TD]Order Number[/TD]
[TD]End User Organization[/TD]
[TD]$ Constant Currency[/TD]
[TD]Day of the Week[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]2/11/2019[/TD]
[TD]19Q4[/TD]
[TD]20Q1[/TD]
[TD]1234567[/TD]
[TD]Made up Organization[/TD]
[TD]$100,000,000[/TD]
[TD]Tuesday[/TD]
[/TR]
</tbody>[/TABLE]
Thank you,
Obligatory "new to VBA"...
I'm trying to create a macro for my boss that would allow him to
1) Add a column to the far right of a table in any workbook
2) Name that column "Day of the week"
3) Find a column in the table with the header "Adj Order Date" and apply a formula in the column created in step 1 that changes the date from (ex: 2/19/2019) to (ex: Tuesday)
4) Refresh the workbook (so that the pivot linked to that table receives the new field titled "Day of the Week")
Rules:
Requirement 1 needs to be variable since he might be adding columns to the table at some point so it won't always be A:G for example.
Requirement 3 needs to be variable since "Adj Order Date" may not always be A1
- I'm guessing that formula would need to be =Text([Adj Order Date],"DDDD")
- I'm also guessing that this formula should autofill because the newly created column will be part of the table
Current Progress:
I'm pretty much stuck after step 1. Any help would be greatly GREATLY appreciated!
'Step 1
Sub Test()
Dim LastCol As String
LastCol = ActiveSheet.ListObjects("Table1").Range.Columns.Count
Columns(LastCol - 0).EntireColumn.Insert
ActiveSheet.Columns(LastCol + 1).Cut
Columns(LastCol - 0).EntireColumn.Insert
'Step 4
ActiveWorkbook.RefreshAll
'Step 4
ActiveWorkbook.RefreshAll
End Sub
Example header and first row from the table1 referenced above:
[TABLE="width: 964"]
<tbody>[TR]
[TD][/TD]
[TD="align: center"]A[/TD]
[TD="align: center"]B[/TD]
[TD="align: center"]C[/TD]
[TD="align: center"]D[/TD]
[TD="align: center"]E[/TD]
[TD="align: center"]F[/TD]
[TD="align: center"]G[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD]Adj Order Date[/TD]
[TD]Adj Fiscal Quarter[/TD]
[TD]Fiscal Quarter[/TD]
[TD]Order Number[/TD]
[TD]End User Organization[/TD]
[TD]$ Constant Currency[/TD]
[TD]Day of the Week[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD]2/11/2019[/TD]
[TD]19Q4[/TD]
[TD]20Q1[/TD]
[TD]1234567[/TD]
[TD]Made up Organization[/TD]
[TD]$100,000,000[/TD]
[TD]Tuesday[/TD]
[/TR]
</tbody>[/TABLE]
Thank you,