?
Solved

VBA to format

Posted on 2016-07-22
3
Medium Priority
?
104 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 total points
ID: 41725547
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
ID: 41726006
great and quick
0
 
LVL 32

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41726169
Thanks for the feedback. :)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
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.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

801 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