Solved

VBA to format

Posted on 2016-07-22
3
77 Views
Last Modified: 2016-07-23
I get some data from the web which i need to format it. I created below code as new to vb i might have taken an lengthy approach.

this is what it does

Once i copy paste data in sheet 1

1.Delete Column A
2.Delete Blank Rows based on column C
3.Add a New sheet with Name "saffolla" - Can i add current day to the file name
4.Copy paste values from Sheet1 to newsheet ("Saffolla 23-07-2016")
5.Change Col to "MM/DD/YYYY" format
6. Autofit all columns in new sheet
7.Update Headings
8. delete sheet1

The challenge that i the macro have to be performed for every new sheet (current day)
and deleting sheet1

Sub FormatIt()
Columns(1).EntireColumn.Delete
 
 Application.ScreenUpdating = False
Columns("C:C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
Application.ScreenUpdating = True

Dim rng As Range
Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Saffola"
Set rng = Worksheets("Sheet1").Range("A1:F2000")
Worksheets("Saffola").Range("A1").Resize(rng.Rows.Count, rng.Columns.Count).Cells.Value = rng.Cells.Value
 
    Dim ws As Worksheet
    Set ws = Worksheets("Saffola")
    Columns(1).NumberFormat = "MM/DD/YYYY"
    
       For Each ws In ActiveWorkbook.Worksheets
        With ws.Rows(1).Font
            .Bold = True
        End With
        Application.Goto [A1]
    Next ws
    Worksheets("Saffola").Columns("A:I").AutoFit
    Sheet1.Delete
End Sub

Open in new window

Book1.xlsx
0
Comment
Question by:Nirvana
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
Comment Utility
Please try this.....
Option Explicit

Sub FormatIt()
Dim sws As Worksheet, dws As Worksheet
Dim lr As Long

Application.ScreenUpdating = False
Set sws = ActiveSheet

sws.Columns(1).Delete
sws.Columns("C").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
lr = sws.Cells.SpecialCells(xlLastCell).Row

Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "Saffola " & Format(Date, "dd-mm-yyyy")
Set dws = ActiveSheet
sws.Range("A1:F" & lr).Copy
dws.Range("A1").PasteSpecial xlPasteValues

dws.Columns(1).NumberFormat = "MM/DD/YYYY"
dws.Rows(1).Font.Bold = True
dws.Columns.AutoFit
dws.Range("A1").Select
    
Application.DisplayAlerts = False
sws.Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

Open in new window

1
 

Author Closing Comment

by:Nirvana
Comment Utility
great and quick
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
Comment Utility
Thanks for the feedback. :)
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now