Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default Selecting the secon column of a separate range

that is what I wanted to explain; what I want is the column number and not
the number of columns. (1 for the range a1:a4 and 3 for the range c1:c4.

Thanks

"JP" wrote:

Are you saying that you are selecting two separate areas of your
worksheet using Ctrl-Click(drag)?

If you highlight A1:A4 and C1:C4 and both are selected,
Selection.Areas.Count will give you the correct number (2).


HTH,
JP


On Jan 15, 9:47 am, filo666 wrote:
Hello, I'm working with graphs, what I want to do is a kind of difficult to
explain, I hope you understand what I'm trying to say.

I have The following data:

a b c d
1 Time Flow pressure permeate
2 1 3 40 .23
3 2 3.2 40.1 .24
4 3 3.2 40 .2

and so on

I press the control key in the cell A1 and I left clik and slide the pointer
from a1 to a4; then I stop pressing the left key of my mouse and go to the
cell c1 and presing the key control I repeat the same operation; then I have
a range composed by two different columns; wath I want VB to do is to tell me
the column number of the first and second selected columns (and thirt,
fourth, or any amount of columns selected)

I must mention that the ranges are allways from left to right and not at the
bottom (and all the ranges are allineated).

what I tried:

g = Selection.Columns.Count; it gives me the number 1 and that is wrong
because I have 2 columns (and I was expecting the value of column c=3).

the range is:

"a1:a4,c1:c4" and not "a1:c4"

I hope you understood.

TIA



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Selecting the secon column of a separate range

Try this (note: I didn't write the function, only the sub). Select
A1:A4 and C1:C4 so that both are selected, then run GetRangeNumbers()
and you will get a message box with the column numbers for each
column.

Sub GetRangeNumbers()
Dim rng As Excel.Range
Dim X As Excel.Range
Set rng = Selection
For Each X In rng.Areas
MsgBox ConvLtrToNum(Mid(X.Cells(1, 1).Address, 2, 1))
Next X
End Sub

Private Function ConvLtrToNum(ByVal LtrIn As String) As Integer
Dim TempChar As String
Dim TempNum As Integer
Dim NumArray() As Integer
TempChar = ""
TempNum = 0
LtrIn = UCase(LtrIn)
For i = 1 To Len(LtrIn)
NumString = ""
' Change Ltr to Number Indicating Place in Alphabet from 01 to 26
TempChar = Mid(LtrIn, i, 1)
ReDim Preserve NumArray(i)
NumArray(i) = Asc(TempChar) - 64
Next
' Our Most Significant Digits Occur to the Left
HighPower = UBound(NumArray()) - 1
' Convert the Number Array using Powers of 26
For i = 1 To UBound(NumArray())
TempNum = TempNum + (NumArray(i) * (26 ^ HighPower))
HighPower = HighPower - 1
Next
ConvLtrToNum = TempNum
End Function


HTH,
JP


On Jan 16, 4:19*am, filo666 wrote:
that is what I wanted to explain; what I want is the column number and not
the number of columns. (1 for the range a1:a4 *and 3 for the range c1:c4..

Thanks



"JP" wrote:
Are you saying that you are selecting two separate areas of your
worksheet using Ctrl-Click(drag)?


If you highlight A1:A4 and C1:C4 and both are selected,
Selection.Areas.Count will give you the correct number (2).


HTH,
JP


On Jan 15, 9:47 am, filo666 wrote:
Hello, I'm working with graphs, what I want to do is a kind of difficult to
explain, I hope you understand what I'm trying to say.


I have The following data:


* * * * * * * a * * * * * * * * b * * * * * * * *c * * * * * * * * * *d
1 * * * Time * * * * * * Flow * * * * * *pressure * * permeate
2 * * * * *1 * * * * * * * * 3 * * * * * * * * *40 * * * * * * * *.23
3 * * * * *2 * * * * * * * * 3.2 * * * * * * * *40.1 * * * * * * .24
4 * * * * *3 * * * * * * * * 3.2 * * * * * * * *40 * * * * * * * *.2


and so on


I press the control key in the cell A1 and I left clik and slide the pointer
from a1 to a4; then I stop pressing the left key of my mouse and go to the
cell c1 and presing the key control I repeat the same operation; then I have
a range composed by two different columns; wath I want VB to do is to tell me
the column number of the first and second selected columns (and thirt,
fourth, or any amount of columns selected)


I must mention that the ranges are allways from left to right and not at the
bottom (and all the ranges are allineated).


what I tried:


g = Selection.Columns.Count; it gives me the number 1 and that is wrong
because I have 2 columns (and I was expecting the value of column c=3).


the range is:


"a1:a4,c1:c4" and not "a1:c4"


I hope you understood.


TIA- Hide quoted text -


- Show quoted text -


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
Summarising a range in a column into a separate column Aidan[_2_] Excel Worksheet Functions 0 March 28th 07 03:06 AM
Summarising a range in a column into a separate column Toppers Excel Worksheet Functions 0 March 28th 07 01:50 AM
Summarising a range in a column into a separate column karmel Excel Worksheet Functions 0 March 28th 07 12:54 AM
selecting a range according to the longest column John Smith Excel Programming 2 August 5th 06 03:40 AM
Selecting Column Range Desert Piranha[_14_] Excel Programming 2 December 10th 05 09:38 PM


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