Results 1 to 6 of 6

need help to add a new row to a table automatically

Threaded View

  1. #1
    Registered User
    Join Date
    01-17-2020
    Location
    israel
    MS-Off Ver
    2015
    Posts
    2

    Post need help to add a new row to a table automatically

    Hi there, i am new to vba coding and i need some help with a code i made.
    I am trying to build a code that will add a new row to a table automatically if the current month is greater then the newest month that is currently in the table
    for example if the latest row shows info for December 2019 than the code will add a new row for January 2020. here is the code i made:
    Sub NewMonthChck()
        
        Dim sh As Worksheet
        Set sh = ThisWorkbook.Sheets("T.value")
        Dim n As Long
        n = sh.Range("A" & Application.Rows.Count).End(xlUp).Row
        If (Month(Now) > Month(Cells("n", 1).Value)) Then
            sh.Range("A" & n + 1).Value = Date
            sh.Range("B" & n + 1).Value = Range("B4").Formula
            sh.Range("C" & n + 1).Value = Range("C4").Formula
            sh.Range("D" & n + 1).Value = Range("D4").Formula
            sh.Range("E" & n + 1).Value = Range("E4").Formula
            sh.Range("F" & n + 1).Value = Range("F4").Formula
            MsgBox "A new month has started"
        End If
    
    End Sub
    When i try to run it, it says
    "run time error 13:
    type mismatch"

    and highlights the if function line...

    Please if anyone can tell me what i am doing wrong it will be of great value to me!!
    Last edited by hereisjohny; 01-19-2020 at 06:19 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code to display text & code in a combo list, but display only code when selected
    By kdestef1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-26-2019, 06:07 PM
  2. [SOLVED] Need help with VBA code. Tons of code seperated in two, second part of code doesn't work.
    By FragaGeddon in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 11-30-2015, 11:46 AM
  3. [SOLVED] Pattern Building VBA Code - Working code, would like to use cleaner code
    By Benisato in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-10-2015, 03:05 PM
  4. [SOLVED] Excel VB code. Message pops up while code running asking question. Code must not wait.
    By Heinrich Venter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-28-2014, 06:10 AM
  5. [SOLVED] VBA code for assigning a numeric code to text; then numeric code populates table
    By cteaster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-14-2014, 08:01 PM
  6. Replies: 2
    Last Post: 03-09-2013, 04:30 AM

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