How to Loop through rows and Columns to Offset Data
Hi,
I would like to know to how to Loop through all rows that have data and offset them by one column (in the the negative direction) and also select cells in all columns that have data in them and offset them to the same column as the previous data.
So this is the code I currently have written myself:
Sub Offset()
Dim Col As Long
Dim Row As Long
Dim myrg As Range
Dim newrow As Integer
Dim newcol As Integer
Col = Application.InputBox(Prompt:="Select Column your working in",Title:="Column", Type:=1)
newcol = Col - 1
Row = 1
newrow = Row + 1
For Row = 1 To 500
For Col = Col To Col + 1
If Cells(Row, Col) > 0 Then Cells(Row, Col).Offset(, newcol).Select
ElseIf Cells(Row, Col) = "" Then GoTo newrow
Next Row
Next Col
End If
End Sub
I used an input box so I can tell excel what column I want to offset first. I want to add a conditional statement to say if there is no data in the cell then to just skip to the next row.
|