Macro Recorder Error

rbeaslin

New Member
Joined
Oct 30, 2008
Messages
16
Office Version
  1. 365
Platform
  1. Windows
I've been trying to figure this one out and its got me.

I have file that I import into Excel from my accounting software. I want to write some simple VBA that will add one more column (named Base), then add a formula on each line of data (=value(left(c2)). When I use the macro recorder on this file, each time i attempt to add the column header "Base", it blows up and goes into recover mode.

I have tried VBA in a clear/new file and have no problems. Something is wrong with my data that im importing, but I cannot see what the problem is. Can anyone else?

How do I attach the file to this post?
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi
You can't attach files to this forum
You can either post a sample of your data using the download on the 2nd line of my tag
OR
Upload the file to one of the many sites such as mediafire.
Note though, a lot of posters won't look at, or download files, from external sites.
I, for instance am not allowed by IT restrictions, to access any download sites.

You could also consider posting a sample of your recorded code. I note your comment regarding using
(=value(left(c2)), which may be a problem in itself, as it should be (=value(left(c2, No of characters)).

HTH
 
Upvote 0
Thank you so much for this; I've not had to post a portion of my sheet before. Below is an example of the sheet in question:
Excel Workbook
ABCDEFG
1REFERSRC.JRNL.IDACCTPOST.AMT.EXTCNTLACCTG.DATEDEPT
2OSAKA1975778138.29OSAKA1/16/20121
3OSAKA1975778223.18OSAKA1/16/20122
4OSAKA1975778424.4OSAKA1/16/20124
5OSAKA1975778616.23OSAKA1/16/20126
632157CLEAR825101325DRIV-ALLOW2/29/20121
2012 Expense Data3
Excel 2010

Im trying to add a column to the right of column G that would be headed by "Base", then the formula above gives me the left two of the ACCT in column C.
 
Upvote 0
Try
Code:
Sub test()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Columns("H:H").Insert Shift:=xlToRight
    Range("H1").Value = "Base"
    With Range("H2")
        .Formula = "=LEFT(C2,2)"
        .AutoFill Destination:=Range("H2:H" & lr)
    End With
End Sub
 
Upvote 0
A bit tighter
Code:
Sub test()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
Columns("H:H").Insert
Range("H1").Value = "Base"
Range("H2:H" & lr).Formula = "=LEFT(C2,2)"
End Sub
 
Upvote 0
As much as i try to understand VBA and play with it, it just takes some experience to do make it easy. Exactly what I needed. Thank you so much, Michael!
 
Upvote 0
Glad it worked....:beerchug:
Just keep recording your macros then try changing stuff to see what happens....Also keep hanging around here and looking at the VBA questions and how they are answered, then test them on your own workbooks to see what happens.
 
Upvote 0
rbeaslin,

As much as i try to understand VBA and play with it, it just takes some experience to do make it easy.


Training / Books / Sites as of 04/05/2012

MrExcel's Products: Books, CDs, Podcasts Discuss topics related to Holy Macro! Products: Learn Excel from MrExcel, VBA and Macros for Microsoft Excel,Holy Macro! It's 2500 VBA Examples CD, Guerilla Data Analysis Using Microsoft Excel and Excel Knowledge Base CD and the MrExcel Podcasts.
http://www.mrexcel.com/forum/forumdisplay.php?f=19

Getting Started with VBA.
http://www.datapigtechnologies.com/ExcelMain.htm

If you are serious about learning VBA try
http://www.add-ins.com/vbhelp.htm

Excel Tutorials and Tips - VBA - macros - training
http://www.mrexcel.com/articles.shtml

Here's a good primer on the scope of variables.
Scope Of Variables And Procedures

See David McRitchie's site if you just started with VBA
http://www.mvps.org/dmcritchie/excel/getstarted.htm

What is a Visual Basic Module?
http://www.emagenit.com/VBA Folder/what_is_a_vba_module.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

Creating custom functions
http://office.microsoft.com/en-us/excel/HA011117011033.aspx

Writing Your First VBA Function in Excel
http://www.exceltip.com/st/Writing_Your_First_VBA_Function_in_Excel/631.html

VBA for Excel (Macros)
http://www.excel-vba.com/excel-vba-contents.htm

VBA Lesson 11: VBA Code General Tips and General Vocabulary
http://www.excel-vba.com/vba-code-2-1-tips.htm

Excel VBA -- Adding Code to a Workbook
http://www.contextures.com/xlvba01.html

Learn to debug:
http://www.cpearson.com/excel/debug.htm

How To: Assign a Macro to a Button or Shape
http://peltiertech.com/WordPress/how-to-assign-a-macro-to-a-button-or-shape/

User Form Creation
http://www.contextures.com/xlUserForm01.html

Excel Tutorials / Video Tutorials - Functions
http://www.contextures.com/xlFunctions02.html

INDEX MATCH - Excel Index Function and Excel Match Function
http://www.contextures.com/xlFunctions03.html

Excel Data Validation
http://www.contextures.com/xlDataVal08.html#Larger
http://www.contextures.com/excel-data-validation-add.html

Your Quick Reference to Microsoft Excel Solutions
http://www.xl-central.com/index.html

New! Excel Recorded Webinars
http://www.datapigtechnologies.com/ExcelMain.htm

Programming The VBA Editor - Created by Chip Pearson at Pearson Software Consulting LLC
This page describes how to write code that modifies or reads other VBA code.
http://www.cpearson.com/Excel/vbe.aspx

VBA and Macros for Microsoft Excel, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel Hacks 100 Industrial-Strength Tips & Tools, by David & Traina Hawley

VBA and Macros for Microsoft Excel 2007, by Bill Jelen "Mr.Excel" and Tracy Syrstad

Excel 2007 Book: you can try this...there is a try before you buy ebook available at this link…

by Stephen/ Bovey, Rob/ Green, John Bullen (Paperback - Feb 11, 2005)
Professional Excel Development

by Rob Bovey, Stephen Bullen, John Green, and Robert Rosenberg (Paperback - Sep 26, 2001)
Excel 2002 VBA: Programmers Reference

DonkeyOte: My Recommended Reading, Volatility
http://www.decisionmodels.com/calcsecretsi.htm

Sumproduct
http://www.xldynamic.com/source/xld.SUMPRODUCT.html

Arrays
http://www.xtremevbtalk.com/showthread.php?t=296012

Pivot Intro
http://peltiertech.com/Excel/Pivots/pivotstart.htm

Email from XL - VBA
http://www.rondebruin.nl/sendmail.htm

Outlook VBA
http://www.outlookcode.com/article.aspx?ID=40

Function Dictionary
http://www.xlfdic.com/

Function Translations
http://www.piuha.fi/excel-function-name-translation/

Dynamic Named Ranges
http://www.contextures.com/xlNames01.html

How to create Excel Dashboards
http://www.contextures.com/excel-dashboards.html
http://chandoo.org/wp/excel-dashboards/
http://chandoo.org/wp/management-dashboards-excel/
http://www.exceldashboardwidgets.com/

Excel Dashboard / Scorecard Ebook
http://www.qimacros.com/excel-dashboard-scorecard.html

Mike Alexander from Data Pig Technologies
Excel 2007 Dashboards & Reports For Dummies

Templates
http://www.cpearson.com/Excel/Topic.aspx
http://www.contextures.com/excel-template-golf-scores.html

Date & Time stamping:
http://www.mcgimpsey.com/excel/timestamp.html

Get Formula / Formats thru custom functions:
http://dmcritchie.mvps.org/excel/formula.htm#GetFormat

A nice informative MS article "Improving Performance in Excel 2007"
http://msdn.microsoft.com/en-us/library/aa730921.aspx

Progress Meters
http://www.andypope.info/vba/pmeter.htm
http://www.xcelfiles.com/ProgressBar.html

And, as your skills increase, try answering posts on sites like:
http://www.mrexcel.com
http://www.excelforum.com
http://www.ozgrid.com
http://www.vbaexpress.com
http://www.excelfox.com
 
Upvote 0
Ha, Ha Hiker95....I knew you'd spot this one.....:wink:
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,632
Latest member
jladair

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top