PC Review


Reply
Thread Tools Rate Thread

column of a input box selected range

 
 
Dennis Chou
Guest
Posts: n/a
 
      1st Aug 2009
I have an inputbox which captures a user selected range.

From this range, i am able to get the column number via range.column

is there a easy way to reference this column in vba?

currently, i'm using range(cell(1,column#),cell(65000,column#)) which seems
like a complicated way to select the column

i'm hoping there's something like column(column#).select


 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      1st Aug 2009
Hi Dennis,

Is the following example what you want?

Dim colNumber As Long

colNumber = 8

Columns(colNumber).Select

--
Regards,

OssieMac


"Dennis Chou" wrote:

> I have an inputbox which captures a user selected range.
>
> From this range, i am able to get the column number via range.column
>
> is there a easy way to reference this column in vba?
>
> currently, i'm using range(cell(1,column#),cell(65000,column#)) which seems
> like a complicated way to select the column
>
> i'm hoping there's something like column(column#).select
>
>
>

 
Reply With Quote
 
Dennis Chou
Guest
Posts: n/a
 
      1st Aug 2009
actually,

how would i reference that in a worksheet function?

This does not appear to work

Range("b2").Value = WorksheetFunction.SumIf( _
Sheets(UserForm1.ID_sheet_name_1).Columns(1).Address, _
Sheets("compare").Range("a2"), _
Sheets(UserForm1.ID_sheet_name_1).Columns(2).Address)


"OssieMac" <(E-Mail Removed)> wrote in message
news:9B0287DD-6376-46EF-90BB-(E-Mail Removed)...
> Hi Dennis,
>
> Is the following example what you want?
>
> Dim colNumber As Long
>
> colNumber = 8
>
> Columns(colNumber).Select
>
> --
> Regards,
>
> OssieMac
>
>
> "Dennis Chou" wrote:
>
>> I have an inputbox which captures a user selected range.
>>
>> From this range, i am able to get the column number via range.column
>>
>> is there a easy way to reference this column in vba?
>>
>> currently, i'm using range(cell(1,column#),cell(65000,column#)) which
>> seems
>> like a complicated way to select the column
>>
>> i'm hoping there's something like column(column#).select
>>
>>
>>



 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      1st Aug 2009
Hello again Dennis,

Address returns a string like the following.
MsgBox Columns(1).Address

Untested but I think your code should be;

Range("b2").Value = WorksheetFunction.SumIf( _
Sheets(UserForm1_ID).Columns(1), _
Sheets("compare").Range("a2"), _
Sheets(UserForm1_ID).Columns(2))

--
Regards,

OssieMac

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      1st Aug 2009
Just for you interest Dennis you can use the address string in lieu of a cell
range that is inserted between double quotes when using in conjunction with
Range.

Range("b2").Value = WorksheetFunction.SumIf( _
Sheets(UserForm1_ID).Range(Columns(1).Address), _
Sheets("compare").Range("a2"), _
Sheets(UserForm1_ID).Range(Columns(2).Address))

Note that Columns(1).Address is a variable that replaces the part between
the double quotes in range("A:A").


--
Regards,

OssieMac


 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      1st Aug 2009
Range("b2").Value = WorksheetFunction.SumIf( _
Sheets(UserForm1.ID_sheet_name_1).Columns(1), _
Sheets("compare").Range("a2").value, _
Sheets(UserForm1.ID_sheet_name_1).Columns(2))

Use ranges for the first and third parm.

(I added the .value because I don't like to depend on the default
properties--but your code doesn't need it.)

untested, uncompiled. I just modified your code.

Dennis Chou wrote:
>
> actually,
>
> how would i reference that in a worksheet function?
>
> This does not appear to work
>
> Range("b2").Value = WorksheetFunction.SumIf( _
> Sheets(UserForm1.ID_sheet_name_1).Columns(1).Address, _
> Sheets("compare").Range("a2"), _
> Sheets(UserForm1.ID_sheet_name_1).Columns(2).Address)
>
> "OssieMac" <(E-Mail Removed)> wrote in message
> news:9B0287DD-6376-46EF-90BB-(E-Mail Removed)...
> > Hi Dennis,
> >
> > Is the following example what you want?
> >
> > Dim colNumber As Long
> >
> > colNumber = 8
> >
> > Columns(colNumber).Select
> >
> > --
> > Regards,
> >
> > OssieMac
> >
> >
> > "Dennis Chou" wrote:
> >
> >> I have an inputbox which captures a user selected range.
> >>
> >> From this range, i am able to get the column number via range.column
> >>
> >> is there a easy way to reference this column in vba?
> >>
> >> currently, i'm using range(cell(1,column#),cell(65000,column#)) which
> >> seems
> >> like a complicated way to select the column
> >>
> >> i'm hoping there's something like column(column#).select
> >>
> >>
> >>


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Input mask date syntax-limit input to a number range =?Utf-8?B?QmlsbGlhbQ==?= Microsoft Access Database Table Design 2 18th Nov 2007 03:37 PM
sheet protection - only selected range to be able to select/input data Corey Microsoft Excel Worksheet Functions 7 13th Feb 2007 05:41 PM
Re: Find last row and column in a selected range Bernie Deitrick Microsoft Excel Programming 0 20th Dec 2006 02:41 PM
Choose data from a selected range and put result in new column Betsy Microsoft Excel Worksheet Functions 2 1st Jul 2006 04:13 AM
Referencing a Column in a Selected Range of Columns Rob G Microsoft Excel Programming 3 21st Oct 2004 05:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:41 AM.