![]() |
Finding the first non-blank cell in a row and then applying a calculation
Hi All,
I need some help. I am trying to use a macro to go row by row and find the first non-blank cell (which should be a number) and then using that as a start point apply a 1/12th calculation to that cell and the next 11 cells, but after that I want the range to go back to zero's. I am familiar with VBA and Macro's but this is more advanced then I am used to. Thanks |
Finding the first non-blank cell in a row and then applying a calculation
somthing like this will loop through a range, then stop and perform a
calculation when a non-blank cell is encountered. Sub findFirstNonBlankCell() Dim myRange As Range Dim myVar As Range Set myRange = Range("A2:A10") 'set range 'begin loop For Each myVar In myRange Set nextVar = myVar.Offset(1, 0) If myVar = "" Then 'test to see if cell is empty Set myVar = nextVar 'proceed to next cell if empty Else 'else perform a calc. myVar.Value = myVar * 2 'peform a calucation End If Next End Sub |
Finding the first non-blank cell in a row and then applying a calculation
this will give you the row of the 1st blank cell in A
Option Explicit Dim Blankrow As Long Sub test() Blankrow = Worksheets("Sheet1").Range("a1").End(xlDown).Row + 1 End Sub range("A" & Blankrow) will give you the cell address -- Gary wrote in message oups.com... Hi All, I need some help. I am trying to use a macro to go row by row and find the first non-blank cell (which should be a number) and then using that as a start point apply a 1/12th calculation to that cell and the next 11 cells, but after that I want the range to go back to zero's. I am familiar with VBA and Macro's but this is more advanced then I am used to. Thanks |
Finding the first non-blank cell in a row and then applying a calculation
Mr Science.
Thanks, this works but how do I get it to stop performing the calculation after a certian number of cells. What I am creating is a revenue recognition model and it needs to find the first cell that has numbers in it and divide that by the number of periods it is being amortized for, but after those periods it needs to stop and look for the next value and do the same thing. Its a bit more dynamic then I am used to. Thanks for your help |
All times are GMT +1. The time now is 03:47 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com