If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VBA Method: Moving Data from One Sheet to Another

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-07-11, 12:55
GLink GLink is offline
Registered User
 
Join Date: Aug 2011
Posts: 17
VBA Method: Moving Data from One Sheet to Another

I am trying to evaluate data in sheet1 and if it fits a certain criteria, do a little math and move the results to a corresponding row in sheet2.

The data is in rows in sheet 1, and I would like the results to be in rows in sheet2 as well.

My VBA is rudimentary. So far, I've been brute-forcing my way around spreadsheets using ActiveCell.Offset.

But now I want to move around two spreadsheets at once. After evaluating a record in sheet1 and writing to sheet2 I want to move down one row in each.

What method do you recommend for this?

Thank you.
Reply With Quote
  #2 (permalink)  
Old 11-09-11, 10:01
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
Don't use ActiveCell.

Use Worksheet.Cells([row], [column]), and use variables that you increment in the code for [row] and [column]. Then you instantly have a handle on where the the results need to go in the other sheet.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
Reply With Quote
  #3 (permalink)  
Old 11-10-11, 14:36
GLink GLink is offline
Registered User
 
Join Date: Aug 2011
Posts: 17
Perfect! That works. Thanks.
Reply With Quote
  #4 (permalink)  
Old 11-11-11, 04:15
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
You're welcome! Good to know it was useful
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
Reply With Quote
  #5 (permalink)  
Old 11-18-11, 11:18
GLink GLink is offline
Registered User
 
Join Date: Aug 2011
Posts: 17
I'm stuck again. :-/ What is the syntax for using variables instead of numbers? My code worked until I replaced the numbers with variables.

I dim r10 etc as integer
Then I set them equal to values

Example code for use is:

initialsum = Sheet10.Cells(r10, ci10)
primingsum = Sheet10.Cells(r10, cpr10)

But I'm getting error 1004 on that. Is my syntax off?
Reply With Quote
  #6 (permalink)  
Old 11-18-11, 11:25
GLink GLink is offline
Registered User
 
Join Date: Aug 2011
Posts: 17
I think I found the error.

When I assigned values to the variables I tried doing two at a time:
c10 = c11 = 3

This doesn't work, although it doesn't either give me an error. Is there a way to assign a value to multiple variables at a time?
Reply With Quote
  #7 (permalink)  
Old 11-18-11, 15:26
weejas weejas is offline
Registered User
 
Join Date: Sep 2006
Location: Surrey, UK
Posts: 448
No. You have to assign variables one at a time, although it's not usually an onerous task to do that.
__________________
10% of magic is knowing something that no-one else does. The rest is misdirection.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On