I am try to have a whole row copied to the next available row in different worksheet within the same workbook if a cell value is numeric.
Sheet "Master" contains thousands of rows of data. there are some blank rows in between these data.
Working sequentially by row through sheet "Master", If cell "AI" on a row has a numeric value (ie: whole number or decimal) then copy it to "Sheet3" in the next available line.
This is what I have so far:
I have a fixed source range because I can't recall how to count total rows and have just be trying to get the rest working before I attempt to tackle that.
My ultimate goal would be to not only get the above working but to add the following so I may use it potentially for future use:
- Instead of having a fixed "sheet 3" destination, create it based on a cell name or sheet name after a test to see if it already created.
- Have a variant that works with non numeric values.
- Have this run on close of the workbook that holds sheet"Master" if possible.
Can anyone see what I am doing wrong? Any assistance would be greatly appreciated.
Sheet "Master" contains thousands of rows of data. there are some blank rows in between these data.
Working sequentially by row through sheet "Master", If cell "AI" on a row has a numeric value (ie: whole number or decimal) then copy it to "Sheet3" in the next available line.
This is what I have so far:
VBA Code:
Sub CopyToOtherSheet()
Dim r As Range
Dim i As Integer
Dim Source As Worksheet
Dim Target As Worksheet
Set Source = ActiveWorkbook.Worksheets("Master")
Set Target = ActiveWorkbook.Worksheets("Sheet3")
j = 1
For Each r In Source.Range("AI:AI1000")
If IsNumeric(r) = True Then
Source.Rows(r.Row).Copy Target.Rows(i)
i = i + 1
End If
Next r
End Sub
I have a fixed source range because I can't recall how to count total rows and have just be trying to get the rest working before I attempt to tackle that.
My ultimate goal would be to not only get the above working but to add the following so I may use it potentially for future use:
- Instead of having a fixed "sheet 3" destination, create it based on a cell name or sheet name after a test to see if it already created.
- Have a variant that works with non numeric values.
- Have this run on close of the workbook that holds sheet"Master" if possible.
Can anyone see what I am doing wrong? Any assistance would be greatly appreciated.