Hello all, This is my first post on MREXCEL.COM. Please be kind. I'm utterly stumped and rather need your help!
Here is a screenshot of some of my Excel sheet.
The range always starts in column H but the last column differs.
Row 5 will always be used for a count of how many visits the column is for - this is hand entered by the user
Row 8 is always the start of the pivoted data but the last row differs
I want to be able to say, where row 5 contains a value > 1 (that's important), then for all entries from row 8 and down within that column, divide the entry in row 8 and below by the value in row 5. Then iterate across all columns.
I have made a complete pig's ear of this and have spent too many hours puzzling over it.
Any help will be much appreciated,
Moley84
Here is a screenshot of some of my Excel sheet.
The range always starts in column H but the last column differs.
Row 5 will always be used for a count of how many visits the column is for - this is hand entered by the user
Row 8 is always the start of the pivoted data but the last row differs
I want to be able to say, where row 5 contains a value > 1 (that's important), then for all entries from row 8 and down within that column, divide the entry in row 8 and below by the value in row 5. Then iterate across all columns.
I have made a complete pig's ear of this and have spent too many hours puzzling over it.
VBA Code:
sourceSheet.Activate
Dim lastrow As Long
Dim lCol As Long
Dim cell As Range
Dim usedRange As Range
Dim VisitCount() As Variant
lastrow = Cells.Find(What:="*", LookIn:=xlValues, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
'I need to use row 5 as there are further columns to the right that don't need this calculation
lCol = sourceSheet.Cells(5, sourceSheet.Columns.Count).End(xlToLeft).Column
'In row 5, column H to last column
VisitCount = Range("h5", Cells(lCol)).Value
'Create the range of where the division needs to occur
Set usedRange = Range("h8" & lCol & lastrow)
' Loop through each cell in the used range
For Each cell In usedRange
' Check if the cell contains a value
If cell.Value > 0 Then
' Within each column, divide the values in the used range with the value above in row 5.
' This next line is not working
usedRange.Replace What:=cell.Value, Replacement:=cell.Value * VisitCount
End If
Next cell
Any help will be much appreciated,
Moley84