Simple VBA code to select cells

normpam

Active Member
Joined
Oct 30, 2002
Messages
354
This code works fine:
Range("E3").Select
Range("E3", Range("E3").Offset(0, 6)).Select

I have always been able to do virtually the same thing using 'ActiveCell' instead of a specific cell, such as E3 in this case, but it just won't work anymore. I keep getting the following error:
Run-time error '1004'
Method Range of object_Global Failed

Has something changed in VBA? I also note that the F8 function key no longer works.....
Thanks!
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
It would need to look like this:
VBA Code:
   Range(Range("E3"), Range("E3").Offset(0, 6)).Select
or more simply, like this:
VBA Code:
   Range("E3").Resize(1, 7).Select
 
Upvote 0
This code works fine:
Range("E3").Select
Range("E3", Range("E3").Offset(0, 6)).Select

I have always been able to do virtually the same thing using 'ActiveCell' instead of a specific cell, such as E3 in this case, but it just won't work anymore. I keep getting the following error:
Run-time error '1004'
Method Range of object_Global Failed

Has something changed in VBA? I also note that the F8 function key no longer works.....
Thanks!
Think I got it... just need to take out the second 'Range' keyword and it works.
 
Upvote 0
Range(ActiveCell) alone is a problem. As for F8 extended selection, maybe you need to reboot or restart Excel? I guess there might be a case where it may not function as usual depending on what your macro or Excel state is at at the time.

VBA Code:
Sub Test()
  Range([E3], [E3].Offset(, 6)).Select
End Sub

Sub Test2()
  Range("E3").Select
  Range(ActiveCell, ActiveCell.Offset(0, 6)).Select
End Sub

Sub Test3()
  MsgBox Range(ActiveCell).Address  'error
End Sub
 
Upvote 0
This
VBA Code:
Range("E3", Range("E3").Offset(0, 6)).Select
Works quite happily for me. Is the sheet protected?
Also F8 in the VBE still steps through the code.
 
Upvote 0
Works quite happily for me. Is the sheet protected?
Also F8 in the VBE still steps through the code.
You are correct. I went back and tried it, and it works for me too.

Might be an issue of protection, as you said.
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,051
Members
448,940
Latest member
mdusw

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