VBA - Setting Range without activating worksheet

vityata

New Member
Joined
Aug 10, 2015
Messages
14
Hello people!
I have the following piece of code, that gets error 400:

Code:
public sub TestMe
Dim range_for_analysis      As Range
 'tbl_master.Activate
Set range_for_analysis = tbl_master.Range(Cells(current_row, STARTING_FROM_COLUMN), Cells(current_row, calendar_cols + COLUMNS_NOT_TOUCHED))
end sub

However, if I uncomment the third line, it works perfectly. Any ideas how to make it work, without using the activation of the spreadsheet?
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
The cells object is missing its reference..

Try this..

Code:
Public Sub TestMe()
   Dim range_for_analysis As Range
   With tbl_master
      Set range_for_analysis = .Range(.Cells(current_row, STARTING_FROM_COLUMN), .Cells(current_row, calendar_cols + COLUMNS_NOT_TOUCHED))
   End With
End Sub
 
Upvote 0
@minimaster -> Good job! I have already starting to live with the idea that I should leave it with the ugly activation :) :)
I would have probably never thought of adding tbl_master to the cells. :)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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