|
-
Oct 8th, 2009, 12:16 PM
#1
Thread Starter
Junior Member
[RESOLVED] [VBA] See if a value exists in a Range
I know this is a common situation but I cannot seem to put this code together. I am trying to take the value of a cell, see if it matches the value in a cell in another group of cells on the same worksheet, and if so update A THIRD cell with a Y/N result, 'exists' in range or 'does not exist' in range.
Thank you for your help.
CWay
-
Oct 8th, 2009, 01:10 PM
#2
Re: [VBA] See if a value exists in a Range
Search the forum on .Find
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 9th, 2009, 02:12 AM
#3
Re: [VBA] See if a value exists in a Range
you can also use worksheet formulas to do this without vba
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 9th, 2009, 02:29 AM
#4
Re: [VBA] See if a value exists in a Range
westconn1 means vlookup - check excels help files
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Oct 9th, 2009, 04:05 AM
#5
Re: [VBA] See if a value exists in a Range
westconn1 means vlookup - check excels help files
or if sumif > 0
actually i meant countif > 0
Last edited by westconn1; Oct 9th, 2009 at 04:33 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 9th, 2009, 05:50 AM
#6
Re: [VBA] See if a value exists in a Range
The thread title says VBA...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Oct 9th, 2009, 07:30 AM
#7
Re: [VBA] See if a value exists in a Range
i read that and offered an alternative, if it was suitable
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Oct 10th, 2009, 08:52 AM
#8
New Member
Re: [VBA] See if a value exists in a Range
I am not good at VBA so I'm sure that my coding is clumsy but it works "touch wood". I use both vba .find from a listbox to match data and the excel vlookup to get related data if match is found. Then I copy and paste the part where I use the excelfunction so it won't be formulas in the sheet. This is what my code snippet looks like if it is of any help, the sub "SaknasVärde" that I call in the first sub could be translated as "MissingValue" and the sub "KlistraIn" copies and paste.
Worksheets("Tidrapport").Activate
Range("A4").Select
Set C = Cells.Find(ComboBox1.Value, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not C Is Nothing Then
C.Offset(Range("$A$3").Value, 0).Activate
Else
Selection.End(xlToRight).Select
Selection.Offset(0, 1).Select
Selection.Value = ComboBox1.Value
Selection.Offset(-1, 0).Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(R[1]C,Lista,3,FALSE)"
SaknasVärde
KlistraIn
Sub Saknasvärde()
If Application.WorksheetFunction.IsNA(ActiveCell.Value) Then
ActiveCell.Value = ""
End If
Well, someone else will surely give you a better code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|