last day (15 days later) » 

9:37 AM
1
A: Extracting value from excel without activating workbook

Siddharth RoutJust remove the line eXwb.Activate. Also remove .Activate from eXwb.Worksheets("Sheet4").Cells.Find(What:=TICKER).Offset(0, 2).Activate Directly work with the range Your code can be written as Set MyXL = GetObject(, "Excel.Application") If MyXL.ActiveWorkbook.Name = "LIST.xlsm" Then Set eX...

 
what is the meaning of run time Error 13 type mismatch? at Set SECTOR = eXwb.Worksheets("Sheet4").Cells.Find(What:=TICKER).Offset(0, 2) I manually checked and found Ticker is exist in workbook.
 
Did you define SECTOR as range? Dim SECTOR As Range
 
yes ! but now I deleted Dim SECTOR As Range altogether and its working.
 
Sorry there is a small change. I have updated the post. you may have to refresh it to see it
 
what if TICKER actually don't exist in workbook? Does it tackle that too?
 
9:37 AM
Yes.. If Not SECTOR Is Nothing Then checka if .Find returned something. You can add an else to that If if you want to do something for example let the user know that ticker was not found. I have updated the post to reflect that
 
I just want to know why my macro is working without adding Dim SECTOR As Range line to the main code? with that I am getting Compiler error Method or data not found at .Offset.
I just want to know why my macro is working without adding Dim SECTOR As Range line to the main code? with that I am getting Compiler error Method or data not found at .Offset.
 
Hi
Are you getting an error with my code? Becuase i tested it before posting
 
your code is fine without Dim SECTOR As Range
and I just want to know why?
 
'~~> Check if .Find returned something
If Not SECTOR Is Nothing Then
Set SECTOR = SECTOR.Offset(, 2)
MsgBox SECTOR.Value
Else
MsgBox "Ticker " & TICKER & " was not found"
End If
Did you try this?
 
TICKER = Selection.Text

' Dim SECTOR As Range
Set SECTOR = eXwb.Worksheets("Sheet4").Cells.Find(What:=TICKER)
'~~> Check if .Find returned something
If Not SECTOR Is Nothing Then
Set SECTOR = SECTOR.Offset(0, 2)
NEWS.Select
Selection.Copy

Selection.MoveRight wdCharacter
Selection.Find.ClearFormatting
Selection.Find.Font.Size = "14"
Selection.Find.Execute SECTOR, , , , , , True
SECTOR = vbNullString
GoTo com
Else
GoTo MANSEC
End If
I am using it like this
here Dim SECTOR As Range is excluded from code and workin just fine
 
9:47 AM
Oh wait.. I know why!!!!
You are doing this from Word and not Excel
Correct?
 
ys brother as i mention early
 
My mistake.. I missed that. Change Dim SECTOR As Range to Dim SECTOR As Object
 
I have updated my post.
 
one last question Is it necessary to Dim variable as object. we know its working without it?
and thanks
 
9:52 AM
It is always good to define your variables/objects :) If you type Option Explicit right at the top of the code then it will force you to declare every variable and object
If you want to read more about good coding practices then you may want to see this

http://www.siddharthrout.com/index.php/2017/12/15/to-err-is-human/
 
Good thanks. appreciate your answer
 
you are welcome. See Ya
 

last day (15 days later) »