0

I am placing a button on a sheet to allow to uppercase all items in two columns in a table.

Here is the code I have found elsewhere and adapted to try to make work:

Private Sub CommandButton1_Click()
 With Range("B10", Cells(Rows.Count, "B").End(xlUp))
        .Value = Evaluate("INDEX(UPPER(" & .Address(External:=True) & "),)")
    End With
With Range("C10", Cells(Rows.Count, "C").End(xlUp))
        .Value = Evaluate("INDEX(UPPER(" & .Address(External:=True) & "),)")
    End With
End Sub

I want the Range to reference Table2, columns 1 & 2 instead of B & C.

Suggestions?

1

1 Answer 1

1

For access to all sorts of table ranges and references, you need to use a ListObject. Here's an example:

Option Explicit

Sub test()
    Dim ws As Worksheet
    Dim t2 As ListObject
    Set ws = ActiveSheet
    Set t2 = ws.ListObjects("Table2")
    Debug.Print t2.ListColumns(1).Name

    Dim refRange As Range
    Set refRange = Union(t2.ListColumns(1).Range, t2.ListColumns(2).Range)
    Debug.Print refRange.Address
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.