Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Sales Schedule

I have a sales schedule with
Col A Description
Col B Date Acquire
Col C Date Sold
Col D Proceeds
Col E Short-term Cost Basis
Col F Long-term Cost Basis
I just want one column for cost basis, so I inserted a column between E and
F and entered a formula: =IF(ISBLANK(E2),G2,E2). I copied the formula down to
F20. I did this as a macro. How can I make this flexible if I add rows (more
sales)? I've searched the site and have tried things like LastRow and
CurrentRegion, but I can't get anyting to work. How do I modify this code to
account for added rows?

ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-1]),RC[1],RC[-1])"
Selection.AutoFill Destination:=Range("F1:F20"), Type:=xlFillDefault
Range("F1:F20").Select


I'll really appreciate your help.
--
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sales Schedule


This will add the formula into Column F of the CurrentRegion, simply
overwrites the formula if it already exists

Code:
--------------------

Dim Rw As Long

Rw = Cells(2, 6).CurrentRegion.Rows.Count
Range(Cells(1, 6), Cells(Rw, 6)).Formula = "=IF(ISBLANK(RC[-1]),RC[1],RC[-1])"
--------------------


--
royUK

Hope that helps, RoyUK
For tips & examples visit 'my web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=35184

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Sales Schedule

Why use a macro? You could put this formula...

=IF(E2="",IF(G2="","",G2),E2)

in F2 and simply copy it down to whatever row you think is the maximum row
you might ever place data in. Nothing will be displayed in any row in Column
F unless there is a value in either Column E or Column G of the row.

--
Rick (MVP - Excel)


"Howard" wrote in message
...
I have a sales schedule with
Col A Description
Col B Date Acquire
Col C Date Sold
Col D Proceeds
Col E Short-term Cost Basis
Col F Long-term Cost Basis
I just want one column for cost basis, so I inserted a column between E
and
F and entered a formula: =IF(ISBLANK(E2),G2,E2). I copied the formula down
to
F20. I did this as a macro. How can I make this flexible if I add rows
(more
sales)? I've searched the site and have tried things like LastRow and
CurrentRegion, but I can't get anyting to work. How do I modify this code
to
account for added rows?

ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-1]),RC[1],RC[-1])"
Selection.AutoFill Destination:=Range("F1:F20"), Type:=xlFillDefault
Range("F1:F20").Select


I'll really appreciate your help.
--
Howard


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default Sales Schedule

Thank you both!

Interesting idea about using a formula.
--
Howard


"Rick Rothstein" wrote:

Why use a macro? You could put this formula...

=IF(E2="",IF(G2="","",G2),E2)

in F2 and simply copy it down to whatever row you think is the maximum row
you might ever place data in. Nothing will be displayed in any row in Column
F unless there is a value in either Column E or Column G of the row.

--
Rick (MVP - Excel)


"Howard" wrote in message
...
I have a sales schedule with
Col A Description
Col B Date Acquire
Col C Date Sold
Col D Proceeds
Col E Short-term Cost Basis
Col F Long-term Cost Basis
I just want one column for cost basis, so I inserted a column between E
and
F and entered a formula: =IF(ISBLANK(E2),G2,E2). I copied the formula down
to
F20. I did this as a macro. How can I make this flexible if I add rows
(more
sales)? I've searched the site and have tried things like LastRow and
CurrentRegion, but I can't get anyting to work. How do I modify this code
to
account for added rows?

ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-1]),RC[1],RC[-1])"
Selection.AutoFill Destination:=Range("F1:F20"), Type:=xlFillDefault
Range("F1:F20").Select


I'll really appreciate your help.
--
Howard



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Sales Schedule

You are ultimately inserting a formula via your macro, so my question dealt
with bypassing the slow, inefficient VB code and place the formula directly
in the cell before hand. True, it puts formulas in cells where none is
required at the time, but Excel should not mind that too much (unless,
maybe, you are filling them to the bottom of the grid).

--
Rick (MVP - Excel)


"Howard" wrote in message
...
Thank you both!

Interesting idea about using a formula.
--
Howard


"Rick Rothstein" wrote:

Why use a macro? You could put this formula...

=IF(E2="",IF(G2="","",G2),E2)

in F2 and simply copy it down to whatever row you think is the maximum
row
you might ever place data in. Nothing will be displayed in any row in
Column
F unless there is a value in either Column E or Column G of the row.

--
Rick (MVP - Excel)


"Howard" wrote in message
...
I have a sales schedule with
Col A Description
Col B Date Acquire
Col C Date Sold
Col D Proceeds
Col E Short-term Cost Basis
Col F Long-term Cost Basis
I just want one column for cost basis, so I inserted a column between E
and
F and entered a formula: =IF(ISBLANK(E2),G2,E2). I copied the formula
down
to
F20. I did this as a macro. How can I make this flexible if I add rows
(more
sales)? I've searched the site and have tried things like LastRow and
CurrentRegion, but I can't get anyting to work. How do I modify this
code
to
account for added rows?

ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-1]),RC[1],RC[-1])"
Selection.AutoFill Destination:=Range("F1:F20"), Type:=xlFillDefault
Range("F1:F20").Select


I'll really appreciate your help.
--
Howard






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Sales Schedule


I the add formula is not part of a routine and is part of a Table you
can set Excel to extend data formats & formulas from the Tools
menu-Options-Edit, this will then copy down formulas as you add to the
table. In 2003 you a create a List option from the Data menu for a
similar effect


--
royUK

Hope that helps, RoyUK
For tips & examples visit 'my web site' (http://www.excel-it.com/)
------------------------------------------------------------------------
royUK's Profile: http://www.thecodecage.com/forumz/member.php?userid=15
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=35184

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking Sales Order to Sales History Data Koomba Excel Worksheet Functions 6 September 30th 08 06:06 AM
Sales Schedule Howard Excel Discussion (Misc queries) 5 September 23rd 08 06:28 PM
Sales Invoicing linked to Sales ledger(Accounts Receivable) Cache Excel Discussion (Misc queries) 0 May 15th 07 03:41 PM
show daily sales as a percentage of monthly sales target Max Bialystock[_2_] Excel Programming 2 April 7th 07 09:11 PM


All times are GMT +1. The time now is 09:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"