Relative referencing??

Saddler

New Member
Joined
May 2, 2002
Messages
8
Hey!
I'm v.new to macros & the like so i need some advise.
I have a task i need to automate as I seem to have to do it manually 10 times a day.
I just need help with the principle really - so, hypothetically, if i was recording a macro to just multiply cell A1*B1 in cell C1,; I could have a file that has just 5 rows with A & B values, but other files may has 20,0000 A & B values.
What is the most efficient way to do this so after the macro runs I have no tidying up to do? - i say this as the way i would do it at the moment is to copy cell C1 through to C65536, and when i get a file with just 6 rows i have to clear the remaining 65531 cells!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
put this in c1 then fill down

this will check if the a1 or b1 is empty if so it will make c1 empty
if a1 and b1 have number in them then it will multiply them

=IF(OR(A1="",B1=""),"",A1*B1)
 
Upvote 0
On 2002-05-03 01:11, Saddler wrote:
Hey!
I'm v.new to macros & the like so i need some advise.
I have a task i need to automate as I seem to have to do it manually 10 times a day.
I just need help with the principle really - so, hypothetically, if i was recording a macro to just multiply cell A1*B1 in cell C1,; I could have a file that has just 5 rows with A & B values, but other files may has 20,0000 A & B values.
What is the most efficient way to do this so after the macro runs I have no tidying up to do? - i say this as the way i would do it at the moment is to copy cell C1 through to C65536, and when i get a file with just 6 rows i have to clear the remaining 65531 cells!

Have a look @ the following;
<pre/>
Sub Tester()

[C1].FormulaR1C1 = "=RC[-2]*RC[-1]"
[C1].AutoFill Destination:=Range("C1:C" & [A1].End(xlDown).Row)

End Sub
</pre>
Assumes
1) Data starts in A1 & B1
2) No gaps in data columns

This places the formula =A1*B1 in C1
(Using R1C1 format)
Uses AutoFill instead of copying
Gets last Row from the VBA use of End(Xldown)
The equavalent Keyboard command is
Selecting a cell and pressing END then the
arrow key...this takes you to the Last populated cell in the specified direction
which in this case is Down.
 
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top