I have lots of data (numbers) with heading in several worksheets that I am trying to zero. This is done on each column as follows: Taking the value of the first row in the column and subtracting this value from all rows in the column.
I have put together this code (may not be the best way, but Im new to VBA so :))
Dim ws As Worksheet
Dim Header As Range, ColData As Range
Dim firstrow As Long
Dim cell As Range, cell2 As Range
Set ws = ActiveSheet
Set Header = ws.Range("B5").End(xlToRight)
For Each cell In Header
If IsEmpty(cell) Then
Else
firstrow = cell.Offset(2).Value
If Not IsEmpty(cell.Offset(2)) Then
Set ColData = ws.Range(cell.Offset(2), cell.Offset(2).End(xlDown))
For Each cell2 In ColData
cell2.Value = cell2.Value - firstrow
Next cell2
Next cell
I am getting the error of Next without For? Am I missing something? forgive me if its something stupid I have checked several times and cant seem to spot it!
Thanks!
EDIT: Fixed IsEmpty function and it ran.. not giving the correct output yet but I'll work on it!
End If's