View Full Version : [SOLVED:] Function to add/write cells
taporctv
06-14-2007, 06:37 AM
Ok I have three columns A, B, C. A1, B1, C1 are column headings.
1st Problem:
I need to perform division between A and B and put the result in C
2nd Problem;
I need to write to A and B.
Can you use variables with Range?
Sheets("Sheet2").Range("B3").CopyFromRecordset RS
How can I make this automated without typing B4,B5,... and so on? How do I throw a variable in there so I can use a loop of some sort?
mdmackillop
06-14-2007, 06:57 AM
http://vbaexpress.com/kb/getarticle.php?kb_id=889
Bob Phillips
06-14-2007, 06:58 AM
Range("C1").Value = Range("A1").Value / Range("B1").Value
'and
For i = 1 To 5
Worksheets("Sheet2").Range("B" & i).CopyFromRecordSet RS
Next i
taporctv
06-14-2007, 07:05 AM
Thanks that worked. I'm new to this vba stuff.
taporctv
06-14-2007, 08:23 AM
Ok a problem arose. Say I delete a2 and b2, a3 and b3 then move up to a2 and b2. How can I stop this?
lucas
06-14-2007, 08:31 AM
these are the same...second is relative:
'Range("C1").Value = Range("A1").Value / Range("B1").Value
Cells(1, 3).Value = Cells(1, 1).Value / Cells(1, 2).Value
mdmackillop
06-14-2007, 01:42 PM
For i = 1 To 5
Worksheets("Sheet2").Range("B" & i).CopyFromRecordSet RS
Next i
In trying this, the whole of the recordset is copied to the range starting at B1. The looping is not repeating the "paste". Similarly, the following only copies for the first line
Worksheets("Sheet1").Range("A1").CopyFromRecordset Rs
Worksheets("Sheet1").Range("A2").CopyFromRecordset Rs
Worksheets("Sheet1").Range("A3").CopyFromRecordset Rs
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.