Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Syntax to select all data

Let me start off by saying I have some programming experience, but am very
new to VBA.
I want to create a macro that will select a range of data, sort it, insert
new lines, and take the sum of the parts. Where I'm hung up on, is that the
data won't always be the same length. I know it will always be the same
width, so the column is not a problem, but how would I go about finding the
bottom-right cell of data? I believe I know how to find the last ROW of
data, but not the specific cell.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Syntax to select all data

If the data is contiguous starting in A1

set rng = range("A1").CurrentRegion
msgbox rng(rng.count).Address

--
Regards,
Tom Ogilvy


"Stephen" wrote in message
...
Let me start off by saying I have some programming experience, but am very
new to VBA.
I want to create a macro that will select a range of data, sort it, insert
new lines, and take the sum of the parts. Where I'm hung up on, is that

the
data won't always be the same length. I know it will always be the same
width, so the column is not a problem, but how would I go about finding

the
bottom-right cell of data? I believe I know how to find the last ROW of
data, but not the specific cell.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Syntax to select all data

Activesheet.range("A:A").End(XLDown)

Returns the range that is the last "used" cell in Column A


"Stephen" wrote:

Let me start off by saying I have some programming experience, but am very
new to VBA.
I want to create a macro that will select a range of data, sort it, insert
new lines, and take the sum of the parts. Where I'm hung up on, is that the
data won't always be the same length. I know it will always be the same
width, so the column is not a problem, but how would I go about finding the
bottom-right cell of data? I believe I know how to find the last ROW of
data, but not the specific cell.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 106
Default Syntax to select all data

Perhaps I am not being clear enough. The data I am referring to will be
import from another sources and not entered manually. I don't know if the
above code will help. I believe this will get me the last row of data:

ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End (xlUp)

but how can I combine that with that last column of data? (It will be column
'H')
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Syntax to select all data

If you didn't have any empty columns or empty rows in that range, Tom's
suggestion may have worked nicely.

But...

dim LastRow as long
dim myRng as range

with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
set myrng = .range("a1:H" & Lastrow)
end with

It still uses column A to find the last used row, though.

Stephen wrote:

Perhaps I am not being clear enough. The data I am referring to will be
import from another sources and not entered manually. I don't know if the
above code will help. I believe this will get me the last row of data:

ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End (xlUp)

but how can I combine that with that last column of data? (It will be column
'H')


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Syntax to select all data

ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell)

"Dave Peterson" wrote:

If you didn't have any empty columns or empty rows in that range, Tom's
suggestion may have worked nicely.

But...

dim LastRow as long
dim myRng as range

with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
set myrng = .range("a1:H" & Lastrow)
end with

It still uses column A to find the last used row, though.

Stephen wrote:

Perhaps I am not being clear enough. The data I am referring to will be
import from another sources and not entered manually. I don't know if the
above code will help. I believe this will get me the last row of data:

ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End (xlUp)

but how can I combine that with that last column of data? (It will be column
'H')


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Syntax to select all data

Ah, but that can be different from what you think it is. It's often way past
what you may think the last cell really is.

Vacation's Over wrote:

ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell)

"Dave Peterson" wrote:

If you didn't have any empty columns or empty rows in that range, Tom's
suggestion may have worked nicely.

But...

dim LastRow as long
dim myRng as range

with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
set myrng = .range("a1:H" & Lastrow)
end with

It still uses column A to find the last used row, though.

Stephen wrote:

Perhaps I am not being clear enough. The data I am referring to will be
import from another sources and not entered manually. I don't know if the
above code will help. I believe this will get me the last row of data:

ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End (xlUp)

but how can I combine that with that last column of data? (It will be column
'H')


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA: Column Select then Data Select then return to cell A1 James C[_2_] Excel Discussion (Misc queries) 3 February 1st 10 11:35 AM
VB Syntax to select a range xjetjockey Excel Discussion (Misc queries) 4 January 17th 07 03:12 AM
Range.Select Using Variables - need syntax gradientS Excel Discussion (Misc queries) 3 February 16th 05 12:45 PM
Select Case syntax Susan Hayes Excel Programming 2 December 4th 04 10:42 PM
Syntax for Excel variable using a SQL Select/From/Where Command... Chip Pearson Excel Programming 0 September 8th 04 11:15 PM


All times are GMT +1. The time now is 12:59 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"