Macro Code to Format Worksheet

June 17, 2009 by vba excel
Filed under: Excel Vba 
Sponsor

Macro Code to Format Worksheet [Q]

We need solution in excel vba macro code to format our worksheet, we regularly importing CSV format data into an Excel worksheet and are
trying to find a method that users can easily apply specific formatting. The
data that is imported varies in numbers of rows and columns imported. Can
this be done with a macro, if yes, how?

If not, can anyone suggests another way of achieving this?

Macro Code to Format Worksheet [A]

This is the solution if your excel data always have the same layouts :

Start a new excel workbook

Start recording a macro that will be stored in this macro workbook.

File|Open your text file that needs to be imported. Format it the way you
like. Insert columns, add headers, freeze panes, widen columns, add filters, do the page setup–everything you can think of. When you’re done, save that workbook with the macro.

I like to put a big button from the Forms toolbar on the only worksheet in that excel vba macro workbook and assign this macro to that big button. I’ll add a few instructions to that sheet, too.

If the file name to open is always the same and in the same location, then I’m about done. If the location or file name changes, I’ll tweak the code to ask for the file.

My tweaked excel vba macro code could look a little like:

Option Explicit
Sub Testme01()

Dim myFileName As Variant
Dim Wkbk as workbook

myFileName = Application.GetOpenFilename(filefilter:=”CSV Files, *.CSV”, _
Title:=”Pick a File”)

If myFileName = False Then
MsgBox “Ok, try later” ‘user hit cancel
Exit Sub
End If

set wkbk = Workbooks.Open(Filename:=Filename:=myFileName)

‘….rest of recorded code here!

End Sub

  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
  • E-mail this story to a friend!
  • Live
  • MisterWong
  • Propeller
  • StumbleUpon
  • Technorati
  • TwitThis
  • YahooMyWeb
  • Print this article!

Rate This Tips:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...


Incoming excel search terms

mss,excel marco remove hyperlink,vba format worksheet,excel marco,excel vba,excel vba copy format,excel vba format sheet,excel vba formatting,vba macro format,excel vba format,excel vba format column,excel vba format text,macro codes,vba macro code,change worksheet format vba,copy format vba,copy worksheet format vba,excel macro format,excel macro to format,excel macro widen column,excel macro worksheet,excel new row same format vba,excel page format macro how to,excel vba code,excel vba format sheet to text,excel vba sheet format,format sheet in vba,format worksheet,macro code,macro for changing date format,macro to widen column in excel,macro vba code,remove excel worksheet format macro,vb code to rename a worksheet in excel,vba date format,vba format column,vba format date,vba format text,vba worksheet format,worksheet open and vba macros,,# ### 00 formating in excel macros,#format vba,0,add new sheet in excel vba,add new worksheet & same & format,add vba code to worksheet,append new row with same format in excel with vba,application getopenfilename filter format,application getopenfilename vba excel open from location



Related Excel Tips

Comments

Have another excel answer or questions for this problem ?
Feel free to post it here..