简体   繁体   中英

Select entire column as range (in worksheet 2) based on user's input i.e 'header name' in a cell / inputbox (in worksheet 1) using vba

Dim ws1 As Worksheet, ws2 As Worksheet

Dim x As Range

Dim valX, valY

Set ws1 = Sheets("Sheet")

valX=ws1.Range("a1").Value

Set x = ws2.Range("a1:J1").Find(What:=valX,LookIn:=xlValues,lookat:=xlWhole)

Above code helps me find the header in new worksheet but i am clueless about selecting the column as Range .

This should select the column, however, remember select is not a good practice in VBA - Disclaimer: in most cases -

ws2.Select    
Columns(x.column).Select

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