Macro to select cells with text

G

Guest

Guest
Hello out there. Can anyone tell me what code might work for the following scenario. If we have a worksheet "A", and let's say there is data in colums A1 to C25 that we want to copy and paste to worksheet "B".

Is there a way to do this where the code will only copy the cells as far down as the text goes? In other words at one time the Worksheet "A" may have information in cells A1 to C25, but on another day, or in another worksheet, the data may stop at row 6. So I can't really say "Copy the data from A1 to C6", because at some point it may be "A1 to C25", or any other row. Is there something that will work for this? I want it to copy the info to Worksheet B, then return to Worksheet A.

Thanks for any help you can offer!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
This code should work it find the last row
You would then need to do the following

location = "a1:c"& lastrow
range(location).select

etc

Hope this helps - code follows:

Sub FindLastRow()
If WorksheetFunction.CountA(Cells) > 0 Then
'Search for any entry, by searching backwards by Rows.
lastrow = Cells.Find(What:="*", After:=[A1], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If
EndofList = lastrow
Range("A1").Select
ActiveCell.Offset(EndofList, 1).Range("A1").Select

End Sub
 
Upvote 0
On 2002-03-06 14:05, Anonymous wrote:
Hello out there. Can anyone tell me what code might work for the following scenario. If we have a worksheet "A", and let's say there is data in colums A1 to C25 that we want to copy and paste to worksheet "B".

Is there a way to do this where the code will only copy the cells as far down as the text goes? In other words at one time the Worksheet "A" may have information in cells A1 to C25, but on another day, or in another worksheet, the data may stop at row 6. So I can't really say "Copy the data from A1 to C6", because at some point it may be "A1 to C25", or any other row. Is there something that will work for this? I want it to copy the info to Worksheet B, then return to Worksheet A.

Thanks for any help you can offer!

Something like:

Range("A1", Range("C65536").Address).Copy _
Destination:=Sheets("B").Range("A1")

will copy your range and paste it on cell A1 in a worksheet named "B".

Regards,
 
Upvote 0

Forum statistics

Threads
1,213,544
Messages
6,114,249
Members
448,556
Latest member
peterhess2002

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