Code from mrExcel's book "VBA and Macros for Excel 2007" is not working

dl7631

Board Regular
Joined
Mar 6, 2009
Messages
114
Hello everyone!
I am new to VBA. I am reading Mr Excel's book "VBA and Macros for Microsoft Office Excel 2007".
I am trying to re-create from scratch and run the code from Chapter 2, pp. 59-60 of the book (see below). I do it using F8. However, as soon as I get to the line that defines a new variable (FinalRow = Cells(Rows.Count, 1).End(xlUp).Row), I get an error:
"Compile error: Variable not defined"

My code is correct (in fact, I copied it from the file I downloaded from the link that was provided in the book)

Advice?
Thank you!
Dimitri


Sub ImportInvoiceFixed()
'
' ImportInvoice Macro
' Written 10/23/2003 by Bill Jelen This macro will import invoice.txt and add totals.
'
' Keyboard Shortcut: Ctrl+i
'
' Workbooks.OpenText Filename:= _
' "C:\invoice.txt", Origin _
' :=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
' , ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True _
' , Space:=False, Other:=False, FieldInfo:=Array(Array(1, 3), Array(2, 1), _
' Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1)), TrailingMinusNumbers _
' :=True
' Find the last row with data. This might change every day
' FinalRow = Range("A65536").End(xlUp).Row - also does not work
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row)
TotalRow = FinalRow + 1
' Build a Total row below this
Range("A" & TotalRow).Value = "Total"
Range("E" & TotalRow).Formula = "=SUM(E2:E" & FinalRow & ")"
Range("E" & TotalRow).Copy Destination:=Range("F" & TotalRow & ":G" & TotalRow)
Rows("1:1").Font.Bold = True
Rows(TotalRow & ":" & TotalRow).Font.Bold = True
Cells.Columns.AutoFit
End Sub
 
You're absolutely right, Dimitri. Best wishes with learning VBA: it takes a while for familiarity with the objects and can be frustrating at the beginning. It gets much easier. Regards, Fazza
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,215,028
Messages
6,122,753
Members
449,094
Latest member
dsharae57

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