PDA

View Full Version : Excel VBA code to get data from a cell.



staicumihai
03-03-2016, 07:01 AM
Hy guys,

I want to make a macro that does the following:

Searches the value 21.02.2014 in column A and if it finds it returns the value in column B (3,4566), if it doesnt find the value in column A returns 0.

Column A Column B
21.02.2014 3,4566
20.13.2013 4,5654
24.12.2015 4,5234
25.02.2013 4,2343

Thanks a lot guys, have a nice day.

JKwan
03-03-2016, 07:37 AM
try this


Sub blah()
Dim Found As Range
Set Found = Find_All("21.02.2014", Range("A:A"))
If Found Is Nothing Then
MsgBox "0"
Else
MsgBox Found.Offset(0, 1)
End If
End Sub
Function Find_All(Find_Item As Variant, Search_Range As Range, _
Optional LookIn As XlFindLookIn = xlValues, _
Optional LookAt As XlLookAt = xlPart, _
Optional MatchCase As Boolean = False) As Range
Dim C As Range, FirstAddress As String
Set Find_All = Nothing
With Search_Range
Set C = .Find( _
what:=Find_Item, _
LookIn:=LookIn, _
LookAt:=LookAt, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=MatchCase, _
searchformat:=False) 'Delete this term for XL2000 and earlier
If Not C Is Nothing Then
Set Find_All = C
FirstAddress = C.Address
Do
Set Find_All = Union(Find_All, C)
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> FirstAddress
End If
End With
End Function