range() range(cells(),cells())

white_flag

Active Member
Joined
Mar 17, 2010
Messages
331
Hello I have this VBA code (part of the code):

Code:
Worksheets(Me.Controls("Combobox1").Value).Range("A2:B10").Copy

an it is working. I try to change it with

Code:
ThisWorkbook.Worksheets(Me.Controls("Combobox1").Value).Range(Cells(2, 1), Cells(ActiveSheet.UsedRange.Columns.Count, ActiveSheet.UsedRange.Rows.Count)).Copy

an it is not going
then I puted like this:

Code:
'Worksheets(Me.Controls("Combobox1").Value).Range(.Cells(2, 1), .Cells(10, 2)).Copy
not going

any idea?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You had the right idea with the 2nd attempt, using the dot on the cells...
Because you must specify book/sheet on the Cells as well as the Range.
but the execution just wasn't quite right.


Try like this

Code:
With ThisWorkbook.Worksheets(Me.Controls("Combobox1").Value)
    .Range(.Cells(2, 1), .Cells(10, 2)).Copy
End With
 
Upvote 0
thank you:
I put this code:
Code:
With ThisWorkbook.Worksheets(Me.Controls("Combobox1").Value)
                .Range(.Cells(25, 1), .Cells(ActiveSheet.UsedRange.Rows.Count,  ActiveSheet.UsedRange.Columns.Count)).Copy
End With
do you have a simple code to find the last used cell in active worksheet
 
Upvote 0
ActiveSheet.Cells.SpecialCells(xlcelltypelastcell)

Try
Code:
With ThisWorkbook.Worksheets(Me.Controls("Combobox1").Value)
    .Range(.Cells(25, 1), .Cells.SpecialCells(xlCellTypeLastCell)).Copy
End With
 
Upvote 0

Forum statistics

Threads
1,224,517
Messages
6,179,239
Members
452,898
Latest member
Capolavoro009

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