putting info from one file into another using vba

J

Jayne22

I am using vba in spreadsheet1 to open and count data from an excel
spreadsheet located online (spreadsheet2). Once that data is counted in
spreadsheet2, I want that value to be printed in spreadsheet1 where the macro
was initially run from. I have the following code so far, but it will
(obviously) print the data in spreadsheet2 rather than spreadsheet1:

Sub openn()
Dim Countt As Long
Workbooks.Open Filename:="sample filename.xls"

Countt = CountColor(Range("D4:GE4"), 45, False) +
CountColor(Range("D4:GE4"), 10, False) + CountColor(Range("d4:GE4"), 8, False)

Range("k53").Value = Countt

End Sub

How do I get it to put that value in spreadsheet1?
 
T

Tom Ogilvy

Sub openn()
Dim Countt As Long
Dim sh as worksheet

set sh = Activesheet
Workbooks.Open Filename:="sample filename.xls"

Countt = CountColor(Range("D4:GE4"), 45, False) +
CountColor(Range("D4:GE4"), 10, False) + CountColor(Range("d4:GE4"), 8, False)

sh.Range("k53").Value = Countt

End Sub
 
J

Jayne22

wow, thanks for your help! This site has been an excellent way to get my
questions answered since I am new to VBA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top