Hello,
I'm trying to copy a row of data from column A - G if column D from row 8 - 209 is blank to the bottom of my spreadsheet.
I used the following coding, but it's copying the whole row instead of up to column G.
Sub Unposted()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 8
LSearchRow = 8
'Start copying data to row 170 in WSO - 480251444 (Op) (row counter variable)
LCopyToRow = 223
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column D = "", copy entire row to WSO - 480251444 (Op)
If Range("D" & CStr(LSearchRow)).Value = "" Then
'Select row in WSO - 480251444 (Op) to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into WSO - 480251444 (Op) in next row
Sheets("WSO - 480251444 (Op)").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Sheet1 to continue searching
Sheets("WSO - 480251444 (Op)").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A4
Application.CutCopyMode = False
Range("A4").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
Please help!!
Configuration: Windows XP Internet Explorer 7.0
I dont actually get what you want, do you want to search til you find a blank row? if so its would be something like this
|
To be honest i know very little about vba i have only done one or two projects in it, i would suggest signing up to technet forums because they have a vba forum with people who are actually experts. But i think you might have to define a range to get it to just take a few columns. It would be something like
|
Assumptions:
|