PC Review


Reply
Thread Tools Rate Thread

Applying formula to variable number of rows

 
 
Shikha
Guest
Posts: n/a
 
      2nd Mar 2009
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,
 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      2nd Mar 2009
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
(E-Mail Removed)
"Shikha" <(E-Mail Removed)> wrote in message
news:1E9A8AB1-E711-4139-9DC8-(E-Mail Removed)...
> 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,


 
Reply With Quote
 
HARSHAWARDHAN. S .SHASTRI
Guest
Posts: n/a
 
      2nd Mar 2009
Shikha,

Pl elaborate the expample with actual data.

H S Shastri



+++++++++++++++++++++++++++++++++++++++++++++++++++

"Shikha" wrote:

> 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,

 
Reply With Quote
 
Shikha
Guest
Posts: n/a
 
      3rd Mar 2009
Thanks Don, it worked well with a single column data. Now, building on this
further, my data is present row wise from A11, A22 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
> (E-Mail Removed)
> "Shikha" <(E-Mail Removed)> wrote in message
> news:1E9A8AB1-E711-4139-9DC8-(E-Mail Removed)...
> > 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,

>
>

 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      3rd Mar 2009
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
(E-Mail Removed)
"Shikha" <(E-Mail Removed)> wrote in message
news:87F7C8A9-ED23-4B32-A713-(E-Mail Removed)...
> Thanks Don, it worked well with a single column data. Now, building on
> this
> further, my data is present row wise from A11, A22 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
>> (E-Mail Removed)
>> "Shikha" <(E-Mail Removed)> wrote in message
>> news:1E9A8AB1-E711-4139-9DC8-(E-Mail Removed)...
>> > 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,

>>
>>


 
Reply With Quote
 
Don Guillett
Guest
Posts: n/a
 
      3rd Mar 2009
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
(E-Mail Removed)
"Don Guillett" <(E-Mail Removed)> wrote in message
news:%23eGFyz$(E-Mail Removed)...
> 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
> (E-Mail Removed)
> "Shikha" <(E-Mail Removed)> wrote in message
> news:87F7C8A9-ED23-4B32-A713-(E-Mail Removed)...
>> Thanks Don, it worked well with a single column data. Now, building on
>> this
>> further, my data is present row wise from A11, A22 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
>>> (E-Mail Removed)
>>> "Shikha" <(E-Mail Removed)> wrote in message
>>> news:1E9A8AB1-E711-4139-9DC8-(E-Mail Removed)...
>>> > 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,
>>>
>>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
variable number of rows. krigger228 Microsoft Excel Programming 2 28th Feb 2009 03:50 PM
Retrieving variable number of rows Amy Blankenship Microsoft Access Queries 2 14th Jul 2008 07:05 PM
Count the Number of Variable Rows Paul Black Microsoft Excel Programming 7 2nd Sep 2007 11:05 AM
Applying auto-filter with large number of rows Hari Microsoft Excel Misc 3 30th Jan 2006 03:06 AM
Need to insert formula to a variable number of rows edoc abv Microsoft Excel Programming 1 26th Sep 2005 04:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:17 PM.