How to ignore a column in a range search VBA code?

Indominus

Board Regular
Joined
Jul 11, 2020
Messages
160
Office Version
  1. 2016
Platform
  1. Windows
Hi. I have a code that searches in a range for a value and returns the matching value from a matching column. I want to know how I can ignore searching in one of the 3 columns in the range as it can have duplicates from the column I need and it returns unnecessary data. In this example I need to ignore column C. Column B and E are the two I really need. I have a value in cell K3. It tries to find it in column E and returns the value in column B. The part of the code for the range is this. Any help is appreciated. Thanks!

VBA Code:
Set rngSrch = srcWs.Range(“B2:E” & LastRow1)
 
The comma is to divide the start and end of the range.
If the comma is outside the quotation marks then it indicates the start and end of the range.
See the examples:

VBA Code:
Sub selectrange()
  'this select E2 to G5
  Range("E2:E5", "G2:G5").Select
  'or
  Range("E2:G5").Select
  'or
  Range("E2", "G5").Select
End Sub

If the comma is inside the quotation marks then it is to select several ranges, try the following examples:

VBA Code:
Sub selectrange2()
  'this select only E2 to E5 and G2 to G5
  Range("E2:E5, G2:G5").Select
  
  'this select only E2 to E5 and G2 to G5 and J2 to J5
  Range("E2:E5, G2:G5, J2:J5").Select
End Sub
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
The comma is to divide the start and end of the range.
If the comma is outside the quotation marks then it indicates the start and end of the range.
See the examples:

VBA Code:
Sub selectrange()
  'this select E2 to G5
  Range("E2:E5", "G2:G5").Select
  'or
  Range("E2:G5").Select
  'or
  Range("E2", "G5").Select
End Sub

If the comma is inside the quotation marks then it is to select several ranges, try the following examples:

VBA Code:
Sub selectrange2()
  'this select only E2 to E5 and G2 to G5
  Range("E2:E5, G2:G5").Select
 
  'this select only E2 to E5 and G2 to G5 and J2 to J5
  Range("E2:E5, G2:G5, J2:J5").Select
End Sub
Ah okay! Makes perfect sense. Will help going forward. Thank you Dante for the super clear explanation and the response. Really appreciate you and everyone else on this community helping others
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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
Back
Top