Select cell without copying it

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm running this macro on word ( there's more to it, like defining oExcel and
so on) and it works fine.

Dim SLOC As String

SLOC = 103810

Dim counter As Integer

For counter = 1 To 10000 Step 1

Selection = osheet.Range("D" & counter) ' Assumes SLOC is on column D

If Selection = SLOC Then

Call fillin

End If

Next counter

The only problem is that when it finds something on column D it writes it to
wherever the cursor is on the word document. This is not ideal.

Is there any way around this, i.e. a way for the macro not to write the
contents of the cell on the word document?

TIA
 
Hard to tell what you are doing, but it looks like you might be using
selection as a variable. If so, use a different variable. If you actually
want to use the selection object, then preface it with the which app.

instead of
if selection = SLOC then

use
if oExcel.Selection = SLOC then

also, this is probably the line where you write to word:
Selection = osheet.Range("D" & counter)

this probably should be

osheet.Range("D" & counter).Select

this could require Excel to have the focus. A better approach would be to
avoid using select and selection.

If osheet.Range("D" & counter).Value = SLOC then


Call fillin

end if
 
Thank You,

that works like a treat

Tom Ogilvy said:
Hard to tell what you are doing, but it looks like you might be using
selection as a variable. If so, use a different variable. If you actually
want to use the selection object, then preface it with the which app.

instead of
if selection = SLOC then

use
if oExcel.Selection = SLOC then

also, this is probably the line where you write to word:
Selection = osheet.Range("D" & counter)

this probably should be

osheet.Range("D" & counter).Select

this could require Excel to have the focus. A better approach would be to
avoid using select and selection.

If osheet.Range("D" & counter).Value = SLOC then


Call fillin

end if
 
Back
Top