I am trying to set my macro file to remove formats from columns that have spaces in them (See CRMCleanup) I tried just adding a Call CRMCleanup piece of code to my UpdateHeadersCRM code but I keep getting an error saying the sheet is still protected. I need to cleanup or merge my code for the CRMCleanup code into the UpdateHeadersCRM code. Any ideas?
Code:
Sub DoWork(wb As Workbook) UpdateHeadersAspirational wb.Sheets("Apsirational") 'The template files have the tab "Aspirational" mispelled as "Apsirational"
UpdateHeadersCRM wb.Sheets("CRM")
End Sub
Code:
Sub ProcessFiles()Dim wb As Workbook
Dim Filename As String, Pathname As String
Pathname = "C:\Users\c755748\Desktop\TEST2\" 'This is the file path the templates need saved to in order for the macro to clean the file formats up in prep for the database
Filename = Dir(Pathname & "*.xlsx")
Do While Filename <> ""
Set wb = Workbooks.Open(Pathname & Filename)
DoWork wb
wb.Close SaveChanges:=True
Filename = Dir()
Loop
End Sub
Code:
Sub UpdateHeadersCRM(ws As Worksheet)
With ws
.Application.ScreenUpdating = False
.Unprotect 'Unprotects the workbook
.Range("A1:W3").Delete Shift:=xlUp 'Need to adjust range if a new column is added or removed
'Re-names row 1 with the column names for the database. Update these fields if a new column is added or removed.
.Range("A1").Value = "WGTD_SLS_CAL_AMT"
.Range("B1").Value = "EST_RVNU_AMT"
.Range("C1").Value = "EST_BPS_AMT"
.Range("D1").Value = "WT_PRC"
.Range("E1").Value = "AVG_BPS_AMT"
.Range("F1").Value = "EST_FDNG_QTR_NM"
.Range("G1").Value = "OPTY_NMBR"
.Range("H1").Value = "CO_NM"
.Range("I1").Value = "CNSLT_NM"
.Range("J1").Value = "PRMY_PRDCT_NM"
.Range("K1").Value = "BTQ_PRMY_PRDCT_TYP_NM"
.Range("L1").Value = "INV_VHCL_2_NM"
.Range("M1").Value = "PLNE_STP_NM"
.Range("N1").Value = "RNKG_TYP_NM"
.Range("O1").Value = "CRNCY_NM"
.Range("P1").Value = "EST_MNDT_AMT"
.Range("Q1").Value = "EST_MNDT_USD_AMT"
.Range("R1").Value = "EST_DCSN_DT"
.Range("S1").Value = "TM_MBR_NM"
.Range("T1").Value = "RGN_4_NM"
.Range("U1").Value = "OPTY_TYP_NM"
.Range("V1").Value = "MOD_DT"
.Range("W1").Value = "STAT_UPDT_TXT"
Call CRMCleanup
End With
End Sub
Code:
Sub CRMCleanup() 'Need to adjust range if a new column is added or removed. This is needed in order to cleanup excess blank columns
Sheets("CRM").Unprotect
Columns("X:AWY").Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Clear
End Sub