LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,124
Default Applying formula to variable number of rows

Sub formulainvariablerows()
lr = Sheets("Sheet1").Cells(Rows.Count, "a").End(xlUp).Row
'lc = Sheets("Sheet1").Cells(1, Columns.Count).End(xlUp).Column
'I changed to
lc = Sheets("Sheet1").Cells(1, Columns.Count).End(xlToLeft).Column

Sheets("result").Cells(2, "a").Resize(lr, lc).Formula = _
"=COUNTIF(Sheet1!A1,Sheet2!A1:AG1)0"

'I added
With Sheets("Result").Range(Cells(2, 1), Cells(lr + 1, lc))
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlEqual, Formula1:="FALSE"
.FormatConditions(1).Interior.ColorIndex = 46
End With
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
The macro does copy the formula into sheet2 from row 2 to the last row on
sheet 1.
If desired, send your wb to my address with a snippet of this and complete
details and before/after examples.


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shikha" wrote in message
...
Thanks Don, it worked well with a single column data. Now, building on
this
further, my data is present row wise from A1:D1, A2:D2 and so on. Its
working
well on A1, A2 but does not percolate row wise. How to do that?
Second query: I also want the conditional formatting that I have applied
on
first row to be applied to variable number of rows below it. Any
suggestions?

"Don Guillett" wrote:

Sub formulainvariablerows()
lr = Sheets("sheet1").Cells(Rows.Count, "a").End(xlUp).Row
'MsgBox lr
Sheets("sheet2").Cells(2, "a").Resize(lr).Formula = "=a1*2"
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Shikha" wrote in message
...
Hi All,
I have 2 worksheets, for which I am comparing data and showing result
in
3rd
worksheet, in same workbook. I am able to do this for fixed number of
rows
by
dragging formula in 'result' sheet to no of rows present in Sheet1 and
Sheet2. However, number of rows in sheet1 and sheet2 is not fixed and
I
want
that formula in 'result' sheet automatically gets copied for no. of
rows
in
sheet1, by a click of a button. Is there any way to do this?

Regards,






 
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
Copy cells to variable number of rows Acct Supr - DCTC Excel Discussion (Misc queries) 5 September 26th 09 12:58 PM
Summing a variable number of rows CEGavinMcGrath Excel Discussion (Misc queries) 4 August 28th 08 10:03 PM
copy down with variable number of rows mohavv Excel Discussion (Misc queries) 5 November 15th 07 04:18 PM
Linking to a Variable Number of Rows - XP/07 RFJ Excel Worksheet Functions 4 May 17th 07 07:53 PM
Applying auto-filter with large number of rows Hari Excel Discussion (Misc queries) 3 January 30th 06 03:06 AM


All times are GMT +1. The time now is 07:17 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"