Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
magix
 
Posts: n/a
Default Check COlumn - Excel VBA

Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B (B11),
if use above code, it will still prompt "It is Column A Only". I want to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.


  #2   Report Post  
Bob Phillips
 
Posts: n/a
Default Check COlumn - Excel VBA

See response in public.excel

--

HTH

RP
(remove nothere from the email address if mailing direct)


"magix" wrote in message
...
Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B

(B11),
if use above code, it will still prompt "It is Column A Only". I want to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.




  #3   Report Post  
Duke Carey
 
Posts: n/a
Default Check COlumn - Excel VBA

if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.


"magix" wrote:

Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B (B11),
if use above code, it will still prompt "It is Column A Only". I want to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.



  #4   Report Post  
Dave Peterson
 
Posts: n/a
Default Check COlumn - Excel VBA

Selection.columns.count will work if the selection is one contiguous range. But
will fail if the selection is multiple discontiguous areas.

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Selection.Columns.Count

One way around it:

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Intersect(Selection.EntireColumn, Rows(1)).Cells.Count

Duke Carey wrote:

if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.

"magix" wrote:

Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B (B11),
if use above code, it will still prompt "It is Column A Only". I want to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.




--

Dave Peterson
  #5   Report Post  
magix
 
Posts: n/a
Default Check COlumn - Excel VBA


"Dave Peterson" wrote in message
...
Selection.columns.count will work if the selection is one contiguous

range. But
will fail if the selection is multiple discontiguous areas.

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Selection.Columns.Count

One way around it:

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Intersect(Selection.EntireColumn, Rows(1)).Cells.Count

Duke Carey wrote:

if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.

"magix" wrote:

Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B

(B11),
if use above code, it will still prompt "It is Column A Only". I want

to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.




--

Dave Peterson


Hi Dave,

You have your point here. If that the case, how can I improve the below
statement ?

" if ActiveCell.Column =1 and selection.columns.count=1 Then"

Regards,
Magix




  #6   Report Post  
Bob Phillips
 
Posts: n/a
Default Check COlumn - Excel VBA

If ActiveCell.Column = 1 And Selection.Columns.Count = 1 And _
Selection.Areas.Count < 1 Then


--

HTH

RP
(remove nothere from the email address if mailing direct)


"magix" wrote in message ...

"Dave Peterson" wrote in message
...
Selection.columns.count will work if the selection is one contiguous

range. But
will fail if the selection is multiple discontiguous areas.

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Selection.Columns.Count

One way around it:

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Intersect(Selection.EntireColumn, Rows(1)).Cells.Count

Duke Carey wrote:

if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.

"magix" wrote:

Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column

B
(B11),
if use above code, it will still prompt "It is Column A Only". I

want
to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.




--

Dave Peterson


Hi Dave,

You have your point here. If that the case, how can I improve the below
statement ?

" if ActiveCell.Column =1 and selection.columns.count=1 Then"

Regards,
Magix




  #7   Report Post  
Dave Peterson
 
Posts: n/a
Default Check COlumn - Excel VBA

Maybe instead of:

if ActiveCell.Column =1 and selection.columns.count=1 Then

This...

if activecell.column = 1 _
and intersect(selection.entirecolumn,rows(1)).cells.co unt = 1 then

This would allow you to select A1:A10 and A21:A30, too.

======
I'm not sure what you want, but maybe you could just use the stuff in column A
after you extend the selection to be the complete row. Selecting B23:G39 would
result in a range of A23:A39.

dim myRng as range
set myrng = intersect(selection.entirerow,range("a:a"))

But that kind of thing depends on what you're really doing.

magix wrote:

"Dave Peterson" wrote in message
...
Selection.columns.count will work if the selection is one contiguous

range. But
will fail if the selection is multiple discontiguous areas.

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Selection.Columns.Count

One way around it:

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Intersect(Selection.EntireColumn, Rows(1)).Cells.Count

Duke Carey wrote:

if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.

"magix" wrote:

Hi,


In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B

(B11),
if use above code, it will still prompt "It is Column A Only". I want

to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.




--

Dave Peterson


Hi Dave,

You have your point here. If that the case, how can I improve the below
statement ?

" if ActiveCell.Column =1 and selection.columns.count=1 Then"

Regards,
Magix


--

Dave Peterson
  #8   Report Post  
magix
 
Posts: n/a
Default Check COlumn - Excel VBA


"Dave Peterson" wrote in message
...
Maybe instead of:

if ActiveCell.Column =1 and selection.columns.count=1 Then

This...

if activecell.column = 1 _
and intersect(selection.entirecolumn,rows(1)).cells.co unt = 1 then

This would allow you to select A1:A10 and A21:A30, too.

======
I'm not sure what you want, but maybe you could just use the stuff in

column A
after you extend the selection to be the complete row. Selecting B23:G39

would
result in a range of A23:A39.

dim myRng as range
set myrng = intersect(selection.entirerow,range("a:a"))

But that kind of thing depends on what you're really doing.

magix wrote:

"Dave Peterson" wrote in message
...
Selection.columns.count will work if the selection is one contiguous

range. But
will fail if the selection is multiple discontiguous areas.

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Selection.Columns.Count

One way around it:

Range("a1:a10,c1:c10,e1:e10").Select
MsgBox Intersect(Selection.EntireColumn, Rows(1)).Cells.Count

Duke Carey wrote:

if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.

"magix" wrote:

Hi,


In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column

A.
Example: When user select cell in column A (A11) and cell in

column B
(B11),
if use above code, it will still prompt "It is Column A Only". I

want
to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.




--

Dave Peterson


Hi Dave,

You have your point here. If that the case, how can I improve the below
statement ?

" if ActiveCell.Column =1 and selection.columns.count=1 Then"

Regards,
Magix


--

Dave Peterson


Thanks again. I think it should be "Selection.Areas.count = 1" instead


  #9   Report Post  
magix
 
Posts: n/a
Default Check COlumn - Excel VBA


"Duke Carey" wrote in message
...
if ActiveCell.Column =1 and selection.columns.count=1 Then

etc.


"magix" wrote:

Hi,

In excel VBA code, I have:

If ActiveCell.Column =1 Then
Msg "It is Column A Only"
Else
Msg "It is NOT Column A"
End If


But How can I check if the selection is actually More than Column A.
Example: When user select cell in column A (A11) and cell in column B

(B11),
if use above code, it will still prompt "It is Column A Only". I want to
avoid that because B11 is included.

I think I should have something like:

If ActiveCell.Column =1 Then
' Check if there is other column included
If there is other column than column A included
Msg "Warning, it's NOT only Column A"
Else
Msg "It is Column A Only"
End If
Else
Msg "It is NOT Column A"
End If

Thanks in advance.

Regards.





Thanks to all of you.


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
Categorizing an excel column Anna Excel Discussion (Misc queries) 2 July 15th 05 07:32 AM
match and count words David Excel Worksheet Functions 5 July 4th 05 02:24 AM
Check boxes in a column BenJAMMIN Excel Discussion (Misc queries) 5 April 9th 05 11:11 PM
Column A is Town, Column B is names. How can Excel add & tell how. Cindy Charts and Charting in Excel 3 January 13th 05 07:27 PM
How do I sort a column of formulas in Excel? Gordon Excel Discussion (Misc queries) 2 November 27th 04 01:55 AM


All times are GMT +1. The time now is 06:28 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"