+ Reply to Thread
Results 1 to 2 of 2

Macro to insert a column and fill that column with word "January"

Hybrid View

  1. #1
    Registered User
    Join Date
    11-21-2012
    Location
    U
    MS-Off Ver
    Excel 2003
    Posts
    23

    Macro to insert a column and fill that column with word "January"

    Hi Can anyone please help?

    I need a macro so that it inserts a column between column A & B and then all cells in new column filled by word "January".

    I tried recording macro but the problem is that it fills all cell in column B upto cell B65000. I need to fill cell only upto where there's data on column A so if column A has data upto 6000 then only upto B6000.

    Any help much appreciated.
    Last edited by aka189; 11-23-2012 at 07:50 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,228

    Re: Macro to insert a column and fill that column with word "January"

    Hi aka189,

    You need to learn to find the last row in a column. Try this code. It isn't cute as it is mostly a recorded macro but I've added a LastRow variable to do what you want.

    Sub JanInColB()
        
        Dim LastRow As Double
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Columns("B:B").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("B2").Select
        ActiveCell.FormulaR1C1 = "January"
        Range("B2").Select
        Selection.Copy
        Range("B3:B" & LastRow).Select
        ActiveSheet.Paste
        Application.CutCopyMode = False
    End Sub
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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