Forum Discussion
Selecting an Excel Range in VBA
I am obviously still confused.
I tried three ways to make the selection based on what I thought you were saying.
Example 1
I am in the "Weekly" worksheet
Dim wsGroups As Worksheet
Set wsGroups = Sheets("Groups")
wsGroups.Range(Cells(2, 2), Cells(34, 12)).Copy 'Get error message on this line of code
Range("A1").Select 'xx
ActiveSheet.Pictures.Paste(Link:=True).Select
Example 2
I am in the "Weekly" worksheet
Dim wsGroups As Worksheet
Set wsGroups = Sheets("Groups")
With wsGroups
.Range(Cells(2, 2), Cells(34, 12)).Copy 'Get error message on this line of code
End With
Example 3
I am in the "Weekly" worksheet
Dim wsGroups As Worksheet
Set wsGroups = Sheets("Groups")
With Sheets("Groups")
.Range(Cells(2, 2), Cells(34, 12)).Copy 'Get error message on this line of code
End With
Range("A1").Select
ActiveSheet.Pictures.Paste(Link:=True).Select
Do you have the name of a good book or other reference on using vba like you are showing me
WallisMcMath I don't have time right now to test and send but the problem before and therefore almost certainly still have in your 3 examples is that "cells" inside the () of the range are trying to refer to a different sheet. see modified examples (changes in red) that I think will fix this problem:
Example 1
I am in the "Weekly" worksheet
Dim wsGroups As Worksheet
Set wsGroups = Sheets("Groups")
wsGroups.Range(wsGroups.Cells(2, 2), wsGroups.Cells(34, 12)).Copy 'Get error message on this line of code
Range("A1").Select 'xx
ActiveSheet.Pictures.Paste(Link:=True).Select
Example 2
I am in the "Weekly" worksheet
Dim wsGroups As Worksheet
Set wsGroups = Sheets("Groups")
With wsGroups
.Range(.Cells(2, 2), .Cells(34, 12)).Copy 'Get error message on this line of code
End With
Example 3
I am in the "Weekly" worksheet
Dim wsGroups As Worksheet
Set wsGroups = Sheets("Groups")
With Sheets("Groups")
.Range(.Cells(2, 2), .Cells(34, 12)).Copy 'Get error message on this line of code
End With
Range("A1").Select
ActiveSheet.Pictures.Paste(Link:=True).Select