VBA search column name

negi

Board Regular
Joined
Apr 16, 2009
Messages
87
Hi expert, im using this code need your help if we can search value from a range.

Sub Demo()
Dim ws As Worksheet
Dim table As ListObject
Dim lstrow As ListRow
Dim r As Long
Dim n As Long
Dim e As Long
Dim strSearch As String
Dim invoice As Range
Dim Cases_sold As Range
Dim rate As Range
Dim a As Range
Dim b As Range
Dim c As Range
' strSearch = "invoice"

Set invoice = Sheet1.Rows(1).Find(what:="Invoice", LookIn:=xlValues, _
lookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'--


Set Cases_sold = Sheet1.Rows(1).Find(what:="cases_sold", LookIn:=xlValues, _
lookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'---

Set rate = Sheet1.Rows(1).Find(what:="rate", LookIn:=xlValues, _
lookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
'----
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
2,259
Office Version
  1. 2016
Platform
  1. Windows
What value you were talking about?

The code will find cells where word Invoice, cases_sold and rate located as range in row 1 where they are named as the words themselves.

Therefore, if you are looking for cell address, then invoice.Address will give the address for example.
 

negi

Board Regular
Joined
Apr 16, 2009
Messages
87
What value you were talking about?

The code will find cells where word Invoice, cases_sold and rate located as range in row 1 where they are named as the words themselves.

Therefore, if you are looking for cell address, then invoice.Address will give the address for example.
Thanks .
i need to pick word from range instead of Invoice, cases_sold and rate.
 

Zot

Well-known Member
Joined
Nov 26, 2020
Messages
2,259
Office Version
  1. 2016
Platform
  1. Windows
the range value will get the result you're looking for :)
 

Forum statistics

Threads
1,185,986
Messages
5,955,163
Members
438,184
Latest member
elea_acero_

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top