referencing the activecell

S

Suzette

I'm stumped. I am wanting to copy information from cells in workbook A to
workbook B. I want to cycle through several rows but would rather not
bounce back and forth activating each WB. Is there a way to reference the
active cell in each workbook?

I tried setting a variable to the worksheet but it doesn't like it.

Set wb1 = ActiveWorkbook
Set ws1 = wb1.Worksheets(2)

Set wb2 = Workbooks.Open(strDir & strFile)
Set ws2 = wb.Worksheets(2)
ws1.Activecell = ws2.Activecell <---- This is the line I want to
use but this code doesn't work.

Thanks in advance.

Suzette
 
B

Bob Phillips

Activecell is not a property of the worksheet, it is a property of the
window, so you only have one.

You will need to keep tags of where you are in each worksheet.

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
I

IanKR

I'm stumped. I am wanting to copy information from cells in workbook
A to workbook B. I want to cycle through several rows but would
rather not bounce back and forth activating each WB. Is there a way
to reference the active cell in each workbook?

I tried setting a variable to the worksheet but it doesn't like it.

Set wb1 = ActiveWorkbook
Set ws1 = wb1.Worksheets(2)

Set wb2 = Workbooks.Open(strDir & strFile)
Set ws2 = wb.Worksheets(2)
ws1.Activecell = ws2.Activecell <---- This is the line I
want to use but this code doesn't work.

Thanks in advance.

Suzette

As well as what Bob has said, watch out for typos - e.g.:

Set ws2 = wb2.Worksheets(2) and not

Set ws2 = wb.Worksheets(2)

This is why it's best to set Option Explicit, as it'll pick up on
typos/errors like this.
 
S

Suzette

Thanks guys. I set it up to reference the cells in both workbooks and it
works perfectly.
 
B

Bob Phillips

I must admit, I wondered whether that was a code typo, or a posting typo <g>

--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 

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