+ Reply to Thread
Results 1 to 3 of 3

Recorded Macro and Sheet# naming issues

  1. #1
    Registered User
    Join Date
    02-13-2014
    Location
    Grimsby, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    2

    Question Recorded Macro and Sheet# naming issues

    Hello, I have a recorded macro that automates a large amount of formatting for me from raw data report. In generating this formatted data from "Sheet1", it creates a new worksheet. This is generally named "Sheet2"

    However, if I delete Sheet 1 and 2 and try to run it again on new raw data - i receive a global error from the macro.

    Help?

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Recorded Macro and Sheet# naming issues

    Post your code.
    Gary's Student

  3. #3
    Registered User
    Join Date
    02-13-2014
    Location
    Grimsby, Ontario
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Recorded Macro and Sheet# naming issues

    ..the code...as requested.

    Sub USED_INVENTORY()
    '
    ' USED_INVENTORY Macro
    '
    ' Keyboard Shortcut: Ctrl+n
    '
    Cells.Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Range("Table3[[#Headers],[Region]]").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    Range("A2").Select
    Application.CutCopyMode = False
    ActiveWindow.SmallScroll Down:=-9
    Columns("A:C").Select
    Selection.Delete Shift:=xlToLeft
    Columns("C:C").Select
    Selection.Delete Shift:=xlToLeft
    Columns("D:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft
    Columns("F:F").Select
    Selection.Style = "Currency"
    Columns("G:G").Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Selection.Delete Shift:=xlToLeft
    Columns("G:G").Select
    Selection.NumberFormat = "[$-409]d-mmm-yy;@"
    Columns("I:I").Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Columns("K:M").Select
    Selection.Delete Shift:=xlToLeft
    Columns("K:K").Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Selection.Style = "Percent"
    Selection.NumberFormat = "0.0%"
    Selection.NumberFormat = "0.00%"
    Columns("L:L").Select
    Selection.Style = "Currency"
    Columns("M:M").Select
    Selection.Style = "Percent"
    Selection.NumberFormat = "0.0%"
    Selection.NumberFormat = "0.00%"
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Columns("N:S").Select
    Selection.Delete Shift:=xlToLeft
    Range("N1").Select
    ActiveCell.FormulaR1C1 = "EstMonthlyInt"
    Range("O1").Select
    ActiveCell.FormulaR1C1 = "EstYearlyInt"
    Range("N2").Select
    ActiveWindow.SmallScroll ToRight:=-3
    ActiveCell.FormulaR1C1 = "=([@AmtOwed]*[@DealerRate])/12"
    Range("O2").Select
    ActiveCell.FormulaR1C1 = "=[@AmtOwed]*[@DealerRate]"
    Columns("N:O").Select
    Selection.Style = "Currency"
    Range("Table3[[#Headers],[DealerNo]]").Select
    Sheets("Sheet1").Select
    Sheets.Add
    Sheets("Sheet1").Select
    Cells.Select
    Selection.Copy
    Sheets("Sheet2").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
    Cells.EntireColumn.AutoFit
    Columns("I:I").Select
    Application.CutCopyMode = False
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Range("A1").Select
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("I2:I245") _
    , SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet2").Sort
    .SetRange Range("A1:O245")
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    Columns("I:I").Select
    Selection.FormatConditions.Add Type:=xlCellValue, Operator:=xlGreater, _
    Formula1:="=89"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 65535
    .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("A1").Select
    ActiveWindow.SmallScroll Down:=-9
    Rows("1:1").Select
    Selection.Font.Bold = True
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
    End With
    Cells.Select
    Cells.EntireColumn.AutoFit
    Range("A1").Select
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Recorded Macro changes to chart name issues
    By tracker1833 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-11-2013, 10:02 AM
  2. [SOLVED] Recorded Pivot Table Macro Doesn't Do What I Recorded!
    By diakonos1984 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-26-2013, 11:01 AM
  3. [SOLVED] excel 2007 chart macro graphs data only from sheet on which macro was recorded
    By JW1028 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-19-2013, 06:33 PM
  4. [SOLVED] Run recorded macro based on current sheet, not the original sheet
    By magillmjl in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 08-22-2012, 06:23 PM
  5. Macro only runs on sheet i recorded it on.
    By BF15 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-20-2011, 07:15 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1