PC Review


Reply
Thread Tools Rate Thread

Count last non blank column and apply to formula

 
 
New Member
Join Date: Jul 2007
Posts: 4
 
      27th Jul 2007
Need a macro that counts from cell A4 until blank column. So lets say the blank column is L4 (11 nonblanks, 1 blank). I need to then offset that by 1 row down and column back so it is K5, I than need to apply that to the formula below and to: lastrow = cells (rows.count, instead of the 1 like it is below i need this to read 11 (because column K is the count of non blank columns = 11). The reason for this is because I have a Pivot table that gets wider and longer at least every month and I need the last column in the pivot table multiplied by $B$1.


Code:
Sub Button1_Click()
Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
Range("a5").Formula = "= """"K5""" * $b$1"
Range("a5").AutoFill Destination:=Range("a5:a" & lastrow)
End Sub
 
Reply With Quote
 
 
 
 
New Member
Join Date: Jul 2007
Posts: 4
 
      30th Jul 2007
Ok I found it out incase anyone else could use this. I am using it on a pivot table that can get larger or smaller.

Quote:
With Sheets("Company").Activate
With Range("b5", Range("b" & Rows.Count).End(xlUp))
x = .Cells(1).End(xlToRight).Offset(1).Address(0, 0)
lastrow = Cells(Rows.Count, 4).End(xlUp).Row
Range("b6").Formula = "=" & x & "*$c$1"
Range("b6").AutoFill Destination:=Range("b6:b" & lastrow)
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("c6").Formula = "=$C$2 * b6"
Range("c6").AutoFill Destination:=Range("c6:c" & lastrow)

Range("b5").End(xlDown).Select
Selection.Copy
Range("c3").Select
Selection.pastespecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("c5").End(xlDown).Select
Selection.Copy
Range("c4").Select
Selection.pastespecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End With
End With
 
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
How do I apply a formula to a whole column at once? Spamlet Microsoft Excel Discussion 3 31st Oct 2010 12:49 AM
how to count#cells w/= value in other column and not count blank c aganoe Microsoft Excel Worksheet Functions 4 9th Apr 2010 11:36 AM
How to apply the same formula to an entire column =?Utf-8?B?TGlzYWI=?= Microsoft Excel New Users 5 9th Aug 2007 04:34 PM
How to check if a cell is blank and, if so, apply a formula Arnold Microsoft Excel Programming 1 27th Dec 2006 09:15 PM
How do I apply formula to entire column =?Utf-8?B?U3RlcGhhbg==?= Microsoft Excel Misc 2 1st Oct 2006 06:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:17 AM.