PDA

View Full Version : FIX code for search variable from copy excel cell or clipboard



danovkos
11-18-2010, 06:39 AM
Hi all,
Please. i cant figured out, how to do following:
I want with macro search
1) value from clipboard
2) value which is copying (CutCopyMode is true) but i can be on other cell. I mean actually i copy cell A1, but my active cell is D5 (i want to search A1)

Of course, if i something in clipboard and then i select copy something from sheet (A1), it will be search by point 2) so A1, because is something copying.

i hope, that i am clear, because my bad english. :(

thx for help
:help :dunno


Sub find_clipboard()
Dim DataObj As MSForms.DataObject
Dim a As Variant
Dim b As Variant
Set DataObj = New MSForms.DataObject
DataObj.GetFromClipboard
a = DataObj.GetText
If Application.IsNumber(a) = True Then
a = DataObj.GetText * 1
End If
If Application.CutCopyMode = xlCopy Then
Cells.Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Else
DataObj.GetFromClipboard
a = DataObj.GetText
Cells.Find(What:=a, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
End If
End Sub

danovkos
11-19-2010, 12:16 AM
nobody can help? :(
maybe can help me only this,
when i copying something (A1) and there is text, it set clipboard to variable DataVariable. If is it text (in cell A1 is text) it set to variable text what is in A1 (this is OK) but also some strange character - maybe is it CR or so..) My variable contains something like this

how can i do from this only pure text withou any other CR?
thx