Home |
Search |
Today's Posts |
#1
![]() |
|||
|
|||
![]()
Hi
I have the current VBA code which works really well in creating and copying data to new tabs. All i want to do is to make sure when it copies over the data in to new tabs that the text formatting copies over too. For example, the column headings are to be bold and the column containing time stays in a time format. Can anyone help? Sub CreateTabs() Dim a, i As Long, j As Long, NR As Long, LR&, ws As Worksheet Dim sName As String Application.ScreenUpdating = False For Each ws In ThisWorkbook.Worksheets If ws.Name < "Data" Then ws.Cells.ClearContents End If Next With Worksheets("Data") a = .Range("a2").CurrentRegion.Value End With For i = 2 To UBound(a) sName = a(i, 1) & "_EMA_FF" If Not Evaluate("=ISREF('" & sName & "'!A1)") Then Worksheets.Add(After:=Worksheets(Worksheets.Count) ).Name = sName End If With Worksheets(sName) NR = .Cells(Rows.Count, "a").End(xlUp).Row + 1 For j = 1 To UBound(a, 2) .Cells(1, j) = a(1, j) .Cells(NR, j) = a(i, j) .Columns.AutoFit Next End With Next End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Here's a revised procedure with some reusable helper routines...
Option Explicit Type udtAppModes Events As Boolean: Display As Boolean CalcMode As Long: CallerID As String End Type Public AppMode As udtAppModes Sub CreateTabs() Const sSource$ = "CreateTabs" '//set procedure 'tag' Dim vDataIn, i&, j&, sName$, ws As Worksheet EnableFastCode sSource For Each ws In ThisWorkbook.Worksheets If ws.Name < "Data" Then ws.Cells.ClearContents Next vDataIn = Sheets("Data").Range("a2").CurrentRegion On Error GoTo cleanup For i = 2 To UBound(vDataIn) sName = vDataIn(i, 1) & "_EMA_FF" If Not bSheetExists(sName) Then _ Sheets.Add(After:=Sheets(Sheets.Count)).Name = sName With Sheets(sName) .Rows(1).Font.Bold = True .Columns("D").NumberFormat = "h:mm:ss AM/PM" '//edit to suit For j = 1 To UBound(vDataIn, 2) .Cells(1, j) = vDataIn(1, j) .Cells(.Cells(.Rows.Count, j).End(xlUp)(2).Row, j) _ = vDataIn(i, j) Next 'j .Columns.AutoFit End With 'Sheets(sName) Next 'i cleanup: EnableFastCode sSource, False End Sub Function bSheetExists(WksName As String) As Boolean ' Checks if a specified worksheet exists. Dim x As Worksheet On Error Resume Next Set x = ActiveWorkbook.Sheets(WksName) bSheetExists = (Err = 0) End Function Sub EnableFastCode(Caller$, Optional SetFast As Boolean = True) 'The following will make sure only the Caller has control, 'and allows any Caller to take control when not in use. If AppMode.CallerID < Caller Then _ If AppMode.CallerID < "" Then Exit Sub With Application If SetFast Then AppMode.Display = .ScreenUpdating: .ScreenUpdating = False AppMode.CalcMode = .Calculation .Calculation = xlCalculationManual AppMode.Events = .EnableEvents: .EnableEvents = False AppMode.CallerID = Caller Else .ScreenUpdating = AppMode.Display .Calculation = AppMode.CalcMode .EnableEvents = AppMode.Events AppMode.CallerID = "" End If End With End Sub -- Garry Free usenet access at http://www.eternal-september.org Classic VB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Automatic addition of Text | Excel Discussion (Misc queries) | |||
format cell if date not current | Excel Worksheet Functions | |||
Date addition/format | Excel Programming | |||
how do i add the same text after current text in multiple cells | Excel Discussion (Misc queries) | |||
I want to sort data randomly in addition to the current descendin. | Excel Worksheet Functions |