VBA Express Forum  




Go Back   VBA Express Forum > VBA Code & Other Help > Excel Help
     Feedback     
Register FAQ Members Arcade Knowledge Base Training Articles Consulting

Reply
 
Thread Tools Display Modes
Old 04-30-2012, 10:18 AM   #1
Yeliz T
 
Yeliz T's Avatar

 
Joined: May 2010
Posts: 120
Kb Entries: 0
Articles: 0
Solved: VBA code to count blank cells in a dynamic range

Hi Everyone ,

I need to edit below script to count blank cells in dynamic range in column F only in Year6. F9 should display the result. At the moment Countblank formula calculates that but when data range changes it doesn't give the right value. I think OFFSET function would work in this case however I was wondering if there is a way to get it done by VBA script?

sample files are attached.

Your help is appreciated.


VBA:
Sub CopyDynamicDataRange() Dim dataWB As Workbook, dataWS As Worksheet Dim baseRng As Range, dataRng As Range Set baseRng = ThisWorkbook.Worksheets("Year6").Range("A55") Set dataWB = Workbooks.Open("S:\Assessment\CB\CBSYr6.xml") With dataWB.Worksheets("Sheet1") Set dataRng = .Range(.Range("A1"), .Range("A1").End(xlToRight)) Set dataRng = .Range(dataRng, dataRng.End(xlDown)) End With Set baseRng = baseRng.Resize(dataRng.Rows.Count, dataRng.Columns.Count) baseRng.Value = dataRng.Value dataWB.Close False End Sub
VBA tags courtesy of www.thecodenet.com
Attached Files To view attachments your post count must be 0 or greater. Your post count is 0 momentarily.


....have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.SJ

Local Time: 12:11 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 04-30-2012, 10:13 PM   #2
Trebor76

 
Joined: Apr 2009
Posts: 140
Kb Entries: 0
Articles: 0
Hi Yeliz T,

You can use this, though bear in mind that the second time you run it the result will be one less as the code has put the result in cell F9 hence reducing the number of blank cells by at least one:

VBA:
Worksheets("Year6").Range("F9").Value = Evaluate("COUNTBLANK(Year6!F1:F" & Worksheets("Year6").Cells(Rows.Count, "F").End(xlUp).Row & ")")
VBA tags courtesy of www.thecodenet.com

HTH

Robert

Last edited by Aussiebear : 04-30-2012 at 11:45 PM. Reason: Corrected the tags surrounding the code

Local Time: 09:11 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Old 05-09-2012, 05:26 AM   #3
Yeliz T
 
Yeliz T's Avatar

 
Joined: May 2010
Posts: 120
Kb Entries: 0
Articles: 0
Hi Robert ,

Sorry for replying late. I used the script you gave me and it's working great. However it didn't reduce number of blank cells even I ran it more than twice.. Anyway this is what I was looking for. Thank you so much for your help. Much appreciated..

Cheers
Yeliz


....have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.SJ

Local Time: 12:11 PM
Local Date: 05-22-2013
Location:

 
Reply With Quote Top
Reply



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -7. The time now is 04:11 AM.


Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright © 2004 - 2012 VBA Express