Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Macro to run formula only on cells with data

I put in the range A7:A5000 so that I made sure the formula ran for all of my
cells, but it is putting in a blank value in all cells below the used rows.
Each file I run this macro on will include a different number of rows. So, I
need to paste the forumla only on rows that have data (are not empty). For
instance, select rows with data, and then paste formula. Right now I have...

Range("A7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[9]&"", ""&RC[10]="", "",IF(RC[1]="""","""",RC[1]),RC[9]&"",
""&RC[10])"
Range("A7").Select
Selection.Copy
Range("A7:A5000").Select
ActiveSheet.Paste

What happens is that when I print the file, it is trying to print rows 1 -
5000!!!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,339
Default Macro to run formula only on cells with data

set last row of data:

lastrow=CELLS(rows.count,"A").end(xlup).row .... last row in Column A

then Range("A7:A" & lastrow) .....??


HTH

"Rob" wrote:

I put in the range A7:A5000 so that I made sure the formula ran for all of my
cells, but it is putting in a blank value in all cells below the used rows.
Each file I run this macro on will include a different number of rows. So, I
need to paste the forumla only on rows that have data (are not empty). For
instance, select rows with data, and then paste formula. Right now I have...

Range("A7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[9]&"", ""&RC[10]="", "",IF(RC[1]="""","""",RC[1]),RC[9]&"",
""&RC[10])"
Range("A7").Select
Selection.Copy
Range("A7:A5000").Select
ActiveSheet.Paste

What happens is that when I print the file, it is trying to print rows 1 -
5000!!!

  #3   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Macro to run formula only on cells with data

be patient with me...

do you mean I should use your suggestion when I select rows where I want to
paste the formula? For instance...


Range("A7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[9]&"", ""&RC[10]="", "",IF(RC[1]="""","""",RC[1]),RC[9]&"",
""&RC[10])"
Range("A7").Select
Selection.Copy
lastrow = Cells(Rows.Count, "A").End(xlUp).Row
Range ("A7:A" & lastrow)


"Toppers" wrote:

set last row of data:

lastrow=CELLS(rows.count,"A").end(xlup).row .... last row in Column A

then Range("A7:A" & lastrow) .....??


HTH

"Rob" wrote:

I put in the range A7:A5000 so that I made sure the formula ran for all of my
cells, but it is putting in a blank value in all cells below the used rows.
Each file I run this macro on will include a different number of rows. So, I
need to paste the forumla only on rows that have data (are not empty). For
instance, select rows with data, and then paste formula. Right now I have...

Range("A7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[9]&"", ""&RC[10]="", "",IF(RC[1]="""","""",RC[1]),RC[9]&"",
""&RC[10])"
Range("A7").Select
Selection.Copy
Range("A7:A5000").Select
ActiveSheet.Paste

What happens is that when I print the file, it is trying to print rows 1 -
5000!!!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro to run formula only on cells with data

I like to just plop the formula into the range--instead of putting it once and
filling down--or copy|pasting.


dim LastRow as long
dim myFormula as string

with activesheet

myformula = "=IF(RC[9]&"", ""&RC[10]=""," _
& """,IF(RC[1]="""","""",RC[1]),RC[9]&"",""&RC[10])"

'I used column B to get the last used row
lastrow = .cells(.rows.count,"B").end(xlup).row

.range("a7:a" & lastrow) = myformula
end with


Rob wrote:

I put in the range A7:A5000 so that I made sure the formula ran for all of my
cells, but it is putting in a blank value in all cells below the used rows.
Each file I run this macro on will include a different number of rows. So, I
need to paste the forumla only on rows that have data (are not empty). For
instance, select rows with data, and then paste formula. Right now I have...

Range("A7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[9]&"", ""&RC[10]="", "",IF(RC[1]="""","""",RC[1]),RC[9]&"",
""&RC[10])"
Range("A7").Select
Selection.Copy
Range("A7:A5000").Select
ActiveSheet.Paste

What happens is that when I print the file, it is trying to print rows 1 -
5000!!!


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
Rob Rob is offline
external usenet poster
 
Posts: 718
Default Macro to run formula only on cells with data

Worked perfectly! Thank you!

"Dave Peterson" wrote:

I like to just plop the formula into the range--instead of putting it once and
filling down--or copy|pasting.


dim LastRow as long
dim myFormula as string

with activesheet

myformula = "=IF(RC[9]&"", ""&RC[10]=""," _
& """,IF(RC[1]="""","""",RC[1]),RC[9]&"",""&RC[10])"

'I used column B to get the last used row
lastrow = .cells(.rows.count,"B").end(xlup).row

.range("a7:a" & lastrow) = myformula
end with


Rob wrote:

I put in the range A7:A5000 so that I made sure the formula ran for all of my
cells, but it is putting in a blank value in all cells below the used rows.
Each file I run this macro on will include a different number of rows. So, I
need to paste the forumla only on rows that have data (are not empty). For
instance, select rows with data, and then paste formula. Right now I have...

Range("A7").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[9]&"", ""&RC[10]="", "",IF(RC[1]="""","""",RC[1]),RC[9]&"",
""&RC[10])"
Range("A7").Select
Selection.Copy
Range("A7:A5000").Select
ActiveSheet.Paste

What happens is that when I print the file, it is trying to print rows 1 -
5000!!!


--

Dave Peterson

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
Formula in macro or in sheet/cells? Heine Excel Worksheet Functions 10 November 3rd 06 11:02 PM
How to use macro to edit data in Excel cells Annamalai Excel Discussion (Misc queries) 11 September 21st 06 07:44 AM
Formula/macro that ignores cells nonblanks pmarques Excel Discussion (Misc queries) 6 February 10th 06 02:55 PM
Macro to delete data in 'green' cells only Steve Excel Worksheet Functions 7 March 19th 05 01:40 PM
repeat macro formula to all cells dave glynn Excel Discussion (Misc queries) 8 March 10th 05 08:42 PM


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

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

About Us

"It's about Microsoft Excel"