Results 1 to 8 of 8

problem missed formulas in TOTAL row when add new columns

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-02-2020
    Location
    Asia
    MS-Off Ver
    2010 insider(Windows 10 64-bit)
    Posts
    817

    problem missed formulas in TOTAL row when add new columns

    Hi
    I got help from Maras_mak in old thread . every thing is ok except one thing is not adding formulas for row TTL for columns Arrived & Sales . the code will insert three columns for next month with the same formatting and formules .
    here is the code
    Option Explicit
    
    Sub InsertMonth()
        Dim rng As Range
        Dim oldmth As String, mystr As String
        Dim oldm As Integer, newm As Integer
        Dim am
        
        am = [{"JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER"}]
        Application.ScreenUpdating = False
        Application.Calculation = xlManual
        With Sheets(1)
            oldmth = (.Cells(1, Columns.Count).End(xlToLeft)(1, 1))
            oldm = Application.Match(oldmth, am, 0)
            newm = Month(DateSerial(Year(Now), oldm + 1, 1))
            
            .Cells(2, Columns.Count).End(xlToLeft)(1, -1).Resize(.[a2].CurrentRegion.Rows.Count - 1, 3).Copy _
                    Cells(2, Columns.Count).End(xlToLeft)(1, 2)
            .Cells(2, Columns.Count).End(xlToLeft)(1, -1).Offset(1).Resize(.[a2].CurrentRegion.Rows.Count, 1).Resize(, 3).ClearContents
            If .Cells(1, Columns.Count).End(xlToLeft)(1, 1).Value <> "JANUARY" Then
                .Cells(2, Columns.Count).End(xlToLeft)(1, -1).Offset(1, -1).Resize(.[a2].CurrentRegion.Rows.Count, 1).Copy
                .Cells(2, Columns.Count).End(xlToLeft)(1, 1).Offset(1).Resize(.[a2].CurrentRegion.Rows.Count, 1).PasteSpecial xlPasteFormulas
            Else
                Sheets("Helper").Cells(2, Columns.Count).End(xlToLeft)(1, 1).Resize(.[a2].CurrentRegion.Rows.Count - 3).Offset(1).Copy
                .Cells(2, Columns.Count).End(xlToLeft)(1, 1).Offset(1).PasteSpecial xlPasteFormulas
            End If
            .Cells(1, Columns.Count).End(xlToLeft)(1, 1).Offset(, 1).Value = _
                            Choose(newm, "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER")
            With .Cells(1, Columns.Count).End(xlToLeft)(1, 1).Resize(, 3)
                .Merge
                .HorizontalAlignment = xlCenter
                .Font.ColorIndex = 1
                .Interior.ColorIndex = 6
                 .Font.Size = 12
    
            End With
            .Cells(2, Columns.Count).End(xlToLeft)(1, 1).Offset(1).Select
            Application.CutCopyMode = False
            Application.Calculation = xlCalculationAutomatic
        End With
    End Sub
    thanks
    Attached Files Attached Files
    Last edited by abdo meghari; 11-28-2022 at 05:43 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with Macro to add Columns with formulas before the "TOTAL" column
    By Cyril_M4 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-21-2022, 03:05 AM
  2. match missed items between two sheets into one column and add the missed
    By abdo meghari in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-08-2022, 02:10 AM
  3. [SOLVED] Power query missed columns when import data
    By afgi in forum Excel Charting & Pivots
    Replies: 15
    Last Post: 03-24-2020, 09:15 AM
  4. Get the number of missed payments and missed payments of interest
    By chergian in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-01-2016, 08:37 PM
  5. 'Fill down formulas in adjacent columns' Problem
    By GreatLakesJK in forum Excel General
    Replies: 0
    Last Post: 12-13-2010, 12:07 PM
  6. Replies: 1
    Last Post: 07-10-2010, 09:38 PM

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