excel VBA function to select the first row in a column and it will will select all cells below it and make it range

JoshD

I'm trying to write a code, I believe it needs to be a function. I want to select the first row in a column and it will create a range with all the rows below it (until empty cell). I think the problem is the syntax for the 'Range'.

(Ultimately my goal is to be ably to select two cells in two different columns, automatically create 2 ranges and plot them against each other in a scatter plot. but I'm struggling with just the first part)

My code looks something like:

`

Function rng1(x as variant)

Dim ji as string, jf as string
Dim rng1 as range

ji=x.Address
jf=x.End(xldown).Address

rng1=Range(ji:jf)

'

DiegoAndresJAY

I removed the variable declaration for "rng1" since you can't name a variable the same as your function. You simply need to concatenate your strings together. You also have to set the function since a range is an object type and not a primitive.

Function rng1(x as variant) as Range

Dim ji as string, jf as string

ji=x.Address
if x.offset(1,0) <> "" then
    jf=x.End(xldown).Address
else
    jf=ji
end if

set rng1=Range(ji & ":" & jf)
End Function

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Excel VBA select range using cells and xlDown

From Dev

Excel VBA How to select variable range of cells

From Dev

Excel: select column in range by column index - no vba

From Dev

Excel VBA Select all cells down

From Dev

VBA Excel select a range of cells within a named range

From Dev

Find Column Header By Name And Select All Data Below Column Header (Excel-VBA)

From Dev

Excel VBA how to select all cells in a dynamic range were the colour index is not 0

From Dev

Excel VBA range select

From Dev

Excel VBA set variable to select a range of cells in a specific worksheet

From Dev

Excel: Conditionally Select Range of Cells Based on Values in Other Column

From Dev

Select all cells with values in A column and text to Columns with VBA

From Dev

VBA: Export Access to Excel -> Select All Cells - > format Table

From Dev

Select cells from function in VBA

From Dev

Select cells from function in VBA

From Dev

Select all blanks cells in a column

From Dev

VBA Select Random Row In Range of Select

From Dev

Find and select first blank cell in column B with Excel vba

From Dev

Excel-VBA Find Function does not consider first row of column

From Dev

How to select range of cells, from first non-black to last non-blank cell (VBA)?

From Dev

Cut n cells and insert to below row using excel vba

From Java

Excel VBA select mulptiple cells based on selection

From Dev

Get column x's Cells from a Range of Cells in Excel VBA

From Dev

Excel - Dynamically select a range from a column in excel

From Dev

Make vba excel function dynamic with the reference cells

From Dev

Select and Copy a range of cells

From Dev

Excel VBA to select a range based on cell value

From Dev

Excel VBA select entire sheet using Range

From Dev

VBA Excel - overflow error on range select

From Dev

Excel VBA select method of range class failed

Related Related

  1. 1

    Excel VBA select range using cells and xlDown

  2. 2

    Excel VBA How to select variable range of cells

  3. 3

    Excel: select column in range by column index - no vba

  4. 4

    Excel VBA Select all cells down

  5. 5

    VBA Excel select a range of cells within a named range

  6. 6

    Find Column Header By Name And Select All Data Below Column Header (Excel-VBA)

  7. 7

    Excel VBA how to select all cells in a dynamic range were the colour index is not 0

  8. 8

    Excel VBA range select

  9. 9

    Excel VBA set variable to select a range of cells in a specific worksheet

  10. 10

    Excel: Conditionally Select Range of Cells Based on Values in Other Column

  11. 11

    Select all cells with values in A column and text to Columns with VBA

  12. 12

    VBA: Export Access to Excel -> Select All Cells - > format Table

  13. 13

    Select cells from function in VBA

  14. 14

    Select cells from function in VBA

  15. 15

    Select all blanks cells in a column

  16. 16

    VBA Select Random Row In Range of Select

  17. 17

    Find and select first blank cell in column B with Excel vba

  18. 18

    Excel-VBA Find Function does not consider first row of column

  19. 19

    How to select range of cells, from first non-black to last non-blank cell (VBA)?

  20. 20

    Cut n cells and insert to below row using excel vba

  21. 21

    Excel VBA select mulptiple cells based on selection

  22. 22

    Get column x's Cells from a Range of Cells in Excel VBA

  23. 23

    Excel - Dynamically select a range from a column in excel

  24. 24

    Make vba excel function dynamic with the reference cells

  25. 25

    Select and Copy a range of cells

  26. 26

    Excel VBA to select a range based on cell value

  27. 27

    Excel VBA select entire sheet using Range

  28. 28

    VBA Excel - overflow error on range select

  29. 29

    Excel VBA select method of range class failed

HotTag

Archive