ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   cant seem to get a function to reference a variable cell? (https://www.excelbanter.com/excel-programming/391871-cant-seem-get-function-reference-variable-cell.html)

Archie

cant seem to get a function to reference a variable cell?
 
I want to ask a user to choose a column (eg input "E", for column E) and then
use this in a function in VB

eg to concatenate two cells A3 and E3, but I want the user to choose, say,
"E".

I can get the input but cant seem to get a function to reference a variable
cell?

Thanks

Tom Ogilvy

cant seem to get a function to reference a variable cell?
 
Sub ABC()
Dim rng as Range
Dim bRes as Boolean
ON error resume next
set rng = Application.InputBox("Select a column", type:=8)
On error goto 0
if rng is nothing then exit sub
set rng = rng(1).EntireColumn
bres = myFunc( rng)
End Sub

Public Function myFunc(myrng as Range) as Boolean
Dim r as Range
On Error goto ErrHandler
set r = Intersect(myrng,ActiveCell.entirecolumn)
r = r.offset(0,-1).value & r.value
myFunc = True
exit function
ErrHandler:
MyFunc = False
End Sub

--
Regards,
Tom Ogilvy




"Archie" wrote:

I want to ask a user to choose a column (eg input "E", for column E) and then
use this in a function in VB

eg to concatenate two cells A3 and E3, but I want the user to choose, say,
"E".

I can get the input but cant seem to get a function to reference a variable
cell?

Thanks



All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com