PC Review


Reply
Thread Tools Rate Thread

Referring to Cells

 
 
PeterM
Guest
Posts: n/a
 
      29th May 2008
I have two workbooks open in Excel 2003. From WorkbookA I need to get the
currrent row number, add 1 to it and copy the contents from WorkbookA to
WorkbookB. Presently I have the following code that works...

Dim CurrentRow as Integer
Windows("workbooka.xls").Activate
CurrentRow = ActiveCell.Row
Range("a" & CurrentRow - 1).Select
Selection.Copy
Windows("workbookb.xls").Activate
Range("D2").Select
ActiveSheet.Paste

When the .Activate is executed, workbooka is displayed, then workbookb is
displayed when the second .Activate is executed...during that time it's
flashing windows all over the place...

my question: is there a way from workbookb to get the active row and cell
contents
from workbooka? this would eliminate the .Activates and appease my users...

thanks in advance for your help!
 
Reply With Quote
 
 
 
 
rsw1984
Guest
Posts: n/a
 
      29th May 2008
Hi

What you can do is you can just simply in Workbook B press "="

Then select WorkbookA so you would get this =[Workbook1]Sheet1!$?$?.

The above question marks showing the Cell Values. once you have done this
you can simply, copy the code =([Workbook1]Sheet1!$?$?)+1

Hope this is what you meant.

Thanks

"PeterM" wrote:

> I have two workbooks open in Excel 2003. From WorkbookA I need to get the
> currrent row number, add 1 to it and copy the contents from WorkbookA to
> WorkbookB. Presently I have the following code that works...
>
> Dim CurrentRow as Integer
> Windows("workbooka.xls").Activate
> CurrentRow = ActiveCell.Row
> Range("a" & CurrentRow - 1).Select
> Selection.Copy
> Windows("workbookb.xls").Activate
> Range("D2").Select
> ActiveSheet.Paste
>
> When the .Activate is executed, workbooka is displayed, then workbookb is
> displayed when the second .Activate is executed...during that time it's
> flashing windows all over the place...
>
> my question: is there a way from workbookb to get the active row and cell
> contents
> from workbooka? this would eliminate the .Activates and appease my users...
>
> thanks in advance for your help!

 
Reply With Quote
 
 
 
 
PeterM
Guest
Posts: n/a
 
      29th May 2008
thanks but I know how to do it via formulas in the worksheet themselves, I
need the VBA code to do it...can you help with that?

"rsw1984" wrote:

> Hi
>
> What you can do is you can just simply in Workbook B press "="
>
> Then select WorkbookA so you would get this =[Workbook1]Sheet1!$?$?.
>
> The above question marks showing the Cell Values. once you have done this
> you can simply, copy the code =([Workbook1]Sheet1!$?$?)+1
>
> Hope this is what you meant.
>
> Thanks
>
> "PeterM" wrote:
>
> > I have two workbooks open in Excel 2003. From WorkbookA I need to get the
> > currrent row number, add 1 to it and copy the contents from WorkbookA to
> > WorkbookB. Presently I have the following code that works...
> >
> > Dim CurrentRow as Integer
> > Windows("workbooka.xls").Activate
> > CurrentRow = ActiveCell.Row
> > Range("a" & CurrentRow - 1).Select
> > Selection.Copy
> > Windows("workbookb.xls").Activate
> > Range("D2").Select
> > ActiveSheet.Paste
> >
> > When the .Activate is executed, workbooka is displayed, then workbookb is
> > displayed when the second .Activate is executed...during that time it's
> > flashing windows all over the place...
> >
> > my question: is there a way from workbookb to get the active row and cell
> > contents
> > from workbooka? this would eliminate the .Activates and appease my users...
> >
> > thanks in advance for your help!

 
Reply With Quote
 
rsw1984
Guest
Posts: n/a
 
      30th May 2008
Sorry I don't do Visual Basic. Why do you need the code for that. I have
answered your original query.

"PeterM" wrote:

> thanks but I know how to do it via formulas in the worksheet themselves, I
> need the VBA code to do it...can you help with that?
>
> "rsw1984" wrote:
>
> > Hi
> >
> > What you can do is you can just simply in Workbook B press "="
> >
> > Then select WorkbookA so you would get this =[Workbook1]Sheet1!$?$?.
> >
> > The above question marks showing the Cell Values. once you have done this
> > you can simply, copy the code =([Workbook1]Sheet1!$?$?)+1
> >
> > Hope this is what you meant.
> >
> > Thanks
> >
> > "PeterM" wrote:
> >
> > > I have two workbooks open in Excel 2003. From WorkbookA I need to get the
> > > currrent row number, add 1 to it and copy the contents from WorkbookA to
> > > WorkbookB. Presently I have the following code that works...
> > >
> > > Dim CurrentRow as Integer
> > > Windows("workbooka.xls").Activate
> > > CurrentRow = ActiveCell.Row
> > > Range("a" & CurrentRow - 1).Select
> > > Selection.Copy
> > > Windows("workbookb.xls").Activate
> > > Range("D2").Select
> > > ActiveSheet.Paste
> > >
> > > When the .Activate is executed, workbooka is displayed, then workbookb is
> > > displayed when the second .Activate is executed...during that time it's
> > > flashing windows all over the place...
> > >
> > > my question: is there a way from workbookb to get the active row and cell
> > > contents
> > > from workbooka? this would eliminate the .Activates and appease my users...
> > >
> > > thanks in advance for your help!

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      30th May 2008
Instead of using the activecell on the worksheet, can you determine it from the
data--like the last used cell in column A???

If yes:

Dim LastRow as Long
dim DestCell as range
Dim WksA as worksheet
dim WksB as worksheet

set wksa = workbooks("workbooka.xls").worksheets("somesheetnamehere")
set wksb = workbooks("workbookb.xls").worksheets("someothersheetnamehere")

with wksa
LastRow = .cells(.rows.count,"A").end(xlup).row
end with

with wksB
set destcell = .cells(.rows.count,"A").end(xlup).offset(1,0)
end with

wksa.rows(lastrow).copy _
destination:=destcell

==========
This actually copies the last used row in wksa to the next available row in
wksb.



PeterM wrote:
>
> I have two workbooks open in Excel 2003. From WorkbookA I need to get the
> currrent row number, add 1 to it and copy the contents from WorkbookA to
> WorkbookB. Presently I have the following code that works...
>
> Dim CurrentRow as Integer
> Windows("workbooka.xls").Activate
> CurrentRow = ActiveCell.Row
> Range("a" & CurrentRow - 1).Select
> Selection.Copy
> Windows("workbookb.xls").Activate
> Range("D2").Select
> ActiveSheet.Paste
>
> When the .Activate is executed, workbooka is displayed, then workbookb is
> displayed when the second .Activate is executed...during that time it's
> flashing windows all over the place...
>
> my question: is there a way from workbookb to get the active row and cell
> contents
> from workbooka? this would eliminate the .Activates and appease my users...
>
> thanks in advance for your help!


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sort a list with cells referring to others cells =?Utf-8?B?RnJpaXMoREsp?= Microsoft Excel Misc 6 24th Feb 2007 04:56 AM
referring by index to adjacent cells =?Utf-8?B?RGVteWFu?= Microsoft Excel Programming 3 8th Aug 2004 07:24 AM
problem referring to Range and Cells =?Utf-8?B?S2V2aW4=?= Microsoft Excel Programming 8 28th Feb 2004 02:05 AM
Selecting a range without referring to specific cells abxy Microsoft Excel Programming 5 9th Feb 2004 02:25 AM
Macro to add cell value to referring cells formula Todd Microsoft Excel Programming 0 16th Sep 2003 08:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:56 AM.