column of a input box selected range

D

Dennis Chou

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
 
O

OssieMac

Hi Dennis,

Is the following example what you want?

Dim colNumber As Long

colNumber = 8

Columns(colNumber).Select
 
D

Dennis Chou

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)
 
O

OssieMac

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))
 
O

OssieMac

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").
 
D

Dave Peterson

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top