Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Looking for a way to Set Range to Entire Column

Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn


For Each R In ColA
If R.Text = "" Then
endrow = R.Row - 1
Exit For
End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line of
my code or do I have to use the first one to set my range ?

Dan Thompson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Looking for a way to Set Range to Entire Column

Set ColA = ActiveSheet.Range("A:A")
--
Gary''s Student - gsnu200854
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Looking for a way to Set Range to Entire Column

Dim ColA As Range
Set ColA = ActiveSheet.Columns(1)
--
If this post helps click Yes
---------------
Jacob Skaria


"Dan Thompson" wrote:

Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn


For Each R In ColA
If R.Text = "" Then
endrow = R.Row - 1
Exit For
End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line of
my code or do I have to use the first one to set my range ?

Dan Thompson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default Looking for a way to Set Range to Entire Column

for the last row in a column

Function LastRow(col As Long) As Long
Dim cell As Range
Set cell = Columns(col).SpecialCells(xlCellTypeLastCell)
LastRow = cell.Row
Set cell = Nothing
End Function



"Dan Thompson" wrote in message
...
Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn


For Each R In ColA
If R.Text = "" Then
endrow = R.Row - 1
Exit For
End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it
does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line
of
my code or do I have to use the first one to set my range ?

Dan Thompson


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Looking for a way to Set Range to Entire Column


ColA is returning a column not the cells in the column.
Try... Msgbox ColA.Count
and then make two changes...

Dim R as Range
Set ColA = ActiveSheet.Columns(1).Cells

Now again try... Msgbox ColA.Count
--
Jim Cone
Portland, Oregon USA



"Dan Thompson"

wrote in message
Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn


For Each R In ColA
If R.Text = "" Then
endrow = R.Row - 1
Exit For
End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line of
my code or do I have to use the first one to set my range ?

Dan Thompson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Looking for a way to Set Range to Entire Column

ActiveSheet.Columns(1) is still correct. Because Columns returns a column
(of cells), there is only one column in it (what Count returns); however,
that column is still made up of 65536 cells (for versions of Excel prior to
2007) which can be seen by simply referencing them...

This returns 1 as an answer...

MsgBox.ActiveSheet.Columns(1).Count

but this returns 65536 as an answer...

MsgBox ActiveSheet.Columns(1).Cells.Count

--
Rick (MVP - Excel)


"Jim Cone" wrote in message
...

ColA is returning a column not the cells in the column.
Try... Msgbox ColA.Count
and then make two changes...

Dim R as Range
Set ColA = ActiveSheet.Columns(1).Cells

Now again try... Msgbox ColA.Count
--
Jim Cone
Portland, Oregon USA



"Dan Thompson"

wrote in message
Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn


For Each R In ColA
If R.Text = "" Then
endrow = R.Row - 1
Exit For
End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it
does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line
of
my code or do I have to use the first one to set my range ?

Dan Thompson


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Looking for a way to Set Range to Entire Column

Rick,
ActiveSheet.Columns(1)
Try looping thru the cells in the column as the original poster wanted to do.
'--
Jim Cone (D582)




"Rick Rothstein"
wrote in message
ActiveSheet.Columns(1) is still correct. Because Columns returns a column
(of cells), there is only one column in it (what Count returns); however,
that column is still made up of 65536 cells (for versions of Excel prior to
2007) which can be seen by simply referencing them...

This returns 1 as an answer...
MsgBox.ActiveSheet.Columns(1).Count

but this returns 65536 as an answer...
MsgBox ActiveSheet.Columns(1).Cells.Count
--
Rick (MVP - Excel)


  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 125
Default Looking for a way to Set Range to Entire Column

Thanks Jim your solution worked

"Jim Cone" wrote:


ColA is returning a column not the cells in the column.
Try... Msgbox ColA.Count
and then make two changes...

Dim R as Range
Set ColA = ActiveSheet.Columns(1).Cells

Now again try... Msgbox ColA.Count
--
Jim Cone
Portland, Oregon USA



"Dan Thompson"

wrote in message
Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn


For Each R In ColA
If R.Text = "" Then
endrow = R.Row - 1
Exit For
End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line of
my code or do I have to use the first one to set my range ?

Dan Thompson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Looking for a way to Set Range to Entire Column

The difference between what you originally posted and what I was attempting
to convey is minimal to be sure. I was just pointing out you could set ColA
to Columns(1) and then just reference its Cells property when needed. You
referenced the Cells property in the Set statement whereas I was (trying) to
indicate it could be referenced when needed. For example, here is the OP's
original loop modified to do this (notice where I referenced the Cells
property)...

Sub Temp()
Dim R As Range
Dim ColA As Range
Dim EndRow As Long
Set ColA = ActiveSheet.Columns(1)
For Each R In ColA.Cells
If R.Text = "" Then
EndRow = R.Row - 1
Exit For
End If
Next
MsgBox EndRow
End Sub

--
Rick (MVP - Excel)


"Jim Cone" wrote in message
...
Rick,
ActiveSheet.Columns(1)
Try looping thru the cells in the column as the original poster wanted to
do.
'--
Jim Cone (D582)




"Rick Rothstein"
wrote in message
ActiveSheet.Columns(1) is still correct. Because Columns returns a column
(of cells), there is only one column in it (what Count returns); however,
that column is still made up of 65536 cells (for versions of Excel prior
to
2007) which can be seen by simply referencing them...

This returns 1 as an answer...
MsgBox.ActiveSheet.Columns(1).Count

but this returns 65536 as an answer...
MsgBox ActiveSheet.Columns(1).Cells.Count
--
Rick (MVP - Excel)



  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Looking for a way to Set Range to Entire Column

On May 22, 1:02*pm, Dan Thompson
wrote:
Here is my code

Sub Temp()
Dim R
'Set ColA = ActiveSheet.Range("A1:A65536")
Set ColA = ActiveSheet.Columns(1).EntireColumn

For Each R In ColA
* * If R.Text = "" Then
* * * * endrow = R.Row - 1
* * * * Exit For
* * End If
Next
MsgBox endrow
End Sub

The first line I have rem'ed out was what I originally was using and it does
work for this code however I was hoping that I could do the same thing by
using just a column reference to set my range for the rest of my code but
when I use the second line after the rem'ed out line it doesn't return the
same as my original line of code. Can I use somthing like the second line of
my code or do I have to use the first one to set my range ?

Dan Thompson


Perhaps I'm overlooking something, but off the top of my head it
appears you're looping thru the entire column from top to bottom
seeking the last used row -- in which case you should be able to save
time/coding by replacing the entire loop with a single line:

sub temp()
endrow = Range("A65536").End(xlUp).End).Row
msgbox endrow
end sub

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
Count Unique Values in a entire column, not just range Brian Excel Worksheet Functions 10 May 16th 09 08:48 PM
When entering data into a range of cells, select the entire range. Q Excel Discussion (Misc queries) 0 September 26th 07 04:36 AM
Can I set a variable to be equal to the range of an entire column? robs3131 Excel Programming 4 June 5th 07 03:14 AM
If data in one column, take date, add 2 days, and turn the entire column a color... [email protected] Excel Discussion (Misc queries) 6 August 24th 06 03:58 AM
how do i set an entire row or column to a range? strataguru[_13_] Excel Programming 7 December 25th 03 04:08 AM


All times are GMT +1. The time now is 07:24 AM.

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"