Problem using variable name

Scott JS

New Member
Joined
Aug 3, 2005
Messages
35
In attempting to write an VBA marco in excel, both of the two pieces of code below return

Run-time error ‘1004’:
Method “Range” of object “_Global” failed

With the second line of code highlighted.

First attempt

Code:
    finalrow = Range("G65536").End(xlUp).Row
    Range("H & finalrow").Select

Second attempt

Code:
    finalrow = Range("G65536").End(xlUp).Row
    Range("H” & “finalrow").Select

I have "dim'ed" finalrow as an integer. What am I doing wrong?
 
I'll try, not sure what you mean by posting data.

i have a spreadsheet with about 20 columns. Need all of the data -- but for the most part, don't need to see to big sections -- columns B-F and H-R
So, I have grouped these so that they can be hidden most of the time.

I am copying subsets of a very large spreadsheet into a similarly structured file, change the name for that recipient, hide the grouped columns and save.

Because I have so many of these to do, I thought it would be simple to automate the copy from one workbook to another, then hide the grouped columns.

Code:
Range("B1:F1").Select
    ExecuteExcel4Macro "SHOW.DETAIL(2,6,FALSE,,1)"
    ActiveCell.Offset(0, 6).Range("A1:K1").Select
    ExecuteExcel4Macro "SHOW.DETAIL(2,18,FALSE,,7)"

The intended function is really independednt of whether there is even any data in the affected columns. Just trying to automate the hiding of an already grouped set of columns.
 
Upvote 0

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,216,101
Messages
6,128,835
Members
449,471
Latest member
lachbee

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