简体   繁体   中英

Find range of column, given column number VBA

How would I find and store a range object for an entire column, given the column number? Thanks!

Use the Columns property

Dim rng as Range
Set rng = ThisWorkbook.Worksheets(1).Columns(12) ' for column 12

How about:

Sub PickAColumn()
   Dim i As Long
   Dim MyColumn As Range
   i = Application.InputBox(Prompt:="Enter Column NUMBER ", Type:=1)
   Set MyColumn = Cells(1, i).EntireColumn

   MyColumn.Select
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM