Help with Sub

claudehollett

Board Regular
Joined
Dec 11, 2003
Messages
89
I'm having trouble with the following Sub. Can someone tell me what is wrong?

I'm trying to select a single cell based on the FinalRow variable as follows:

Sub test()
FinalRow = Range("A65536").End(xlUp).Row
Range(Cells(FinalRow - 2, 34)).Select

End Sub

Thanks for any help.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You want to use either Range or Cells--not both.

The Cells property will accept either the column number as you are using, or the column letter (entered with quotes, e.g. "AH"):
Cells(FinalRow - 2, 34).Select
Cells(FinalRow - 2, "AH").Select

The Range property needs the column letters and the & symbol, as you are essentially building a reference such as "AH3". The & symbol connects the two parts :
Range("AH" & FinalRow -2).Select
 
Upvote 0
Hi claudehollett

You can also select the cell directly

Sub test()
Range("A65536").End(xlUp).Offset(-2, 33).Select

End Sub

Hope this helps
PGC
 
Upvote 0
It should be pointed out, however that depending on what you are wanting to do it is highly possible that you needn't select the cell(s) in the first place. You can usually interact with them directly. For example, if you color a cell yellow, the macro recorder will give you this:
Code:
Range("A1").Select
Selection.Interior.ColorIndex = 6

This will do the exact same thing, just without needing to select the cell:
Code:
Range("A1").Interior.ColorIndex = 6
 
Upvote 0

Forum statistics

Threads
1,203,201
Messages
6,054,088
Members
444,702
Latest member
patrickmg17

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