Select Range From Last Cell

Zanatos1986

New Member
Joined
Apr 15, 2010
Messages
48
I have code that uses two drop down lists to determine which sheet to access in my workbook. These sheets have data that only exist on row A, From A1 to A##
I need to determine the last column being used to get my range (i.e. A1:A34), select and copy this range to past back on Sheet1

I have found numerous code to find the last column but I can never seem to select the cells I want. Any help would be great!



Private Sub Worksheet_Change(ByVal Target As Range)

' Select the XXX
If Target.Address = "$E$10" Then
Select Case Target.Value
Case "XXX"
Call Macro1

Case "XX"
Call Macro2

Case ""
Call Macro3
End Select
End If

' Select The XXXX
If Target.Address = "$E$12" Then
'MsgBox Target.Value
Sheets(Target.Value).Select


Dim lRow As Long
lRow = Range("A" & Rows.Count).End(xlUp).Row
Range(ActiveCell, Range("A" & lRow)).Select


End If

End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Maybe:

Code:
With ThisWorkbook.Sheets(Target.Value)
   lRow = .Range("A" & .Rows.Count).End(xlUp).Row
   .Range("A1:A" & lRow).Copy ... 'destination of the copy action
End With

PS: Please use code tags when you paste VBA code on the forum.
To add code tags, you should type in your post:

Code:
then paste your code, and lastly, type:

['/code]

WITHOUT the ' in front of the /

Thanks for the consideration.
 
Upvote 0
This worked for selecting my cell range perfectly, but I am having a difficult time getting the data to go where I want.

Once I have selected this data range I want it to go back to Sheet1 and auto populate into a ActiveX TextBox with Scrollbar. I have the scroll box setup, but I am not sure how to make the data populate into it. I was thinking to take my data range and creating a name for it (since it is ever changing) and have my textbox reference that, but I'm not sure if that would work. I am very new to ActiveX controls.

I have tried a couple of things to move my data into the TextBox but I don't know how other than copy and paste, and when I do that and record a macro I can't replicate what I did...


Code:
' Select The XXX
If Target.Address = "$E$12" Then
   'MsgBox Target.Value
   Sheets(Target.Value).Select
   
   
Dim lRow As Long
With ThisWorkbook.Sheets(Target.Value)
   lRow = .Range("A" & .Rows.Count).End(xlUp).Row
   .Range("A1:A" & lRow).Select
End With
   
   
End If
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,672
Members
452,937
Latest member
Bhg1984

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