Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7015477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:39:25+00:00 2026-05-27T22:39:25+00:00

I am trying to create an excel macro which is probably going to end

  • 0

I am trying to create an excel macro which is probably going to end up being quite large, to make things easier I am tackling it a bit at a time. So far I have….

Sub Macro4()
'
' Test Macro
'
  'Selects the product_name column by header name
  Dim rngAddress As Range
  Set rngAddress = Range("A1:Z1").Find("product_name")
  If rngAddress Is Nothing Then
  MsgBox "The product_name column was not found."
  Exit Sub
  End If
  Range(rngAddress, rngAddress.End(xlDown)).Select

  'Inserts new column to the left of the product_name column
   Selection.Insert Shift:=xlToRight

  'Re-selects the product_name column
   Range(rngAddress, rngAddress.End(xlDown)).Select

  'Copys the contents of the product_name column
   Selection.Copy
   Selection.Paste

End Sub

I want it to do the following….

  • Search the spreadsheet for the header name ‘product_name’
  • Insert a blank column to the left of the ‘product_name’ column
  • Copy the contents of the ‘product_name’ column
  • Paste them into the newly created blank column
  • Change the header name in this new column to ‘product_name_2’

Currently it works fine up until the pasting into this newly created column, then i get a

'Run-time error '438'; - Object doesn't support this property or method'

Can anyone suggest where i am going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:39:26+00:00Added an answer on May 27, 2026 at 10:39 pm

    Your error is:

    Range(rngAddress, rngAddress.End(xlDown)).Select
    

    This selects from the top of the column down to just above the first blank cell. The insert shifts this portion of the column right leaving the rest where it is. When you select again you are likely to get a larger range because you have mixed two columns. The copy fails because you are then trying to copy values over the top of values.

    If that does not make sense, step through your macro with F8 and see what is happening at each step.

    When you understand why your current macro does not work, try this:

    Sub Macro5()
    
      Dim rngAddress As Range
      Dim ColToBeCopied As Integer
    
      Set rngAddress = Range("A1:Z1").Find("'product_name")
      If rngAddress Is Nothing Then
        MsgBox "The product_name column was not found."
        Exit Sub
      End If
    
      ColToBeCopied = rngAddress.Column
      Columns(ColToBeCopied).EntireColumn.Insert
      Columns(ColToBeCopied + 1).Copy Destination:=Columns(ColToBeCopied)
    
    End Sub
    

    Note:

    1. I did not select anything.
    2. I have left the code operating on the active sheet but it is better to use With Sheets("XXX") … End With.

    Answer to second question

    The macro recorder is not good at showing how to address individual cells systematically.

    With Sheets("xxxx")
      .Cells(RowNum,ColNum).Value = "product_name 1"
    End With
    

    The above uses With which I recommend. Notice the dot in front of Cells.

    The one below operates on the active sheet.

    Cells(RowNum,ColNum).Value = "product_name 1"
    

    RowNum must be a number. ColNum can be a number (say 5) or a letter (say “E”).

    In your case RowNum is 1 and ColNum is ColToBeCopied and ColToBeCopied + 1.

    P.S.

    I forgot to mention that to find the botton row of a column use:

    RowLast = Range(Rows.Count, ColNum).End(xlUp).Row
    

    That is move up from the bottom not down from the top.

    P.S. 2

    To specify a range using Cells:

    .Range(.Cells(Top,Left),.Cells(Bottom,Right))
    

    The dots must match: all three or none.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a macro in Excel which will allow me to
I'm trying to create Excel 2007 Documents programmatically. Now, there are two ways I've
I'm trying to create a new Excel file using jxl, but am having a
I'm trying to create an OleDb connection to an Excel file that is located
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I'm trying to automating some tests for an Excel add-in, which is in xll
I am trying to create a Macro that either runs on close or on
I'm trying to make a macro in VBA for Delmia. That macro need to
I am trying to create dynamic excel sheet, with the help of php using
I'm trying to create a multi-sheet excel document, and thus far I'd been doing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.