Human_doing
Board Regular
- Joined
- Feb 16, 2011
- Messages
- 137
Hi all,
Can anyone please explain why this code doesn't loop through all worksheets in the workbook and perform the formatting on each?
Any help much appreciated
Thanks
Can anyone please explain why this code doesn't loop through all worksheets in the workbook and perform the formatting on each?
Code:
[FONT=Arial]Private Sub CommandButton1_Click()[/FONT]
[FONT=Arial]'Ask user to select Excel file[/FONT]
[FONT=Arial]NewFN = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls), *.xls", Title:="Select the file with raw data for the report")[/FONT]
[FONT=Arial]If NewFN = False Then[/FONT]
[FONT=Arial]' They pressed Cancel[/FONT]
[FONT=Arial]MsgBox "Stopping because you did not select a file"[/FONT]
[FONT=Arial]Exit Sub[/FONT]
[FONT=Arial]Else[/FONT]
[FONT=Arial]Workbooks.Open Filename:=NewFN[/FONT]
[FONT=Arial]End If[/FONT]
[FONT=Arial]Dim Sh As Worksheet<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT]
[FONT=Arial] <o:p></o:p>[/FONT]
[FONT=Arial] For Each Sh In ActiveWorkbook.Worksheets<o:p></o:p>[/FONT]
[FONT=Arial] With Sh[/FONT]
[FONT=Arial]'Unmerge all cells[/FONT]
[FONT=Arial] Cells.Select[/FONT]
[FONT=Arial] Selection.MergeCells = False[/FONT]
[FONT=Arial]'Delete unnecessary columns and rows[/FONT]
[FONT=Arial] Columns("A:A").Select[/FONT]
[FONT=Arial] Selection.Delete Shift:=xlToLeft[/FONT]
[FONT=Arial] Rows("1:3").Select[/FONT]
[FONT=Arial] Selection.Delete Shift:=xlUp[/FONT]
[FONT=Arial]Next Sh[/FONT]
[FONT=Arial]End Sub [/FONT]
Any help much appreciated
Thanks