ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   goto next if (https://www.excelbanter.com/excel-programming/417541-goto-next-if.html)

Miree

goto next if
 
I have 8 columns of user entered data which i need to copy into another
worksheet.
I have the code to move it over but not all 8 colums will be filled all the
time and i dont want to copy over blank lines. I want to write code to say if
cell 1 is empty donot copy go to cell 2, then if cell 2 is empty, donot copy
goto cell 3..... and so on.
it may be that random colums have data so i need it to check each one.

Mike H

goto next if
 
Post your code

"Miree" wrote:

I have 8 columns of user entered data which i need to copy into another
worksheet.
I have the code to move it over but not all 8 colums will be filled all the
time and i dont want to copy over blank lines. I want to write code to say if
cell 1 is empty donot copy go to cell 2, then if cell 2 is empty, donot copy
goto cell 3..... and so on.
it may be that random colums have data so i need it to check each one.


joel

goto next if
 

Sub MoveData()

NewRow = 1
With Sheets("Sheet1")

LastRow = 0
For ColCount = 0 To 8
LRow = .Cells(Rows.Count, ColCount).End(xlUp).Row
If LRow LastRow Then
LastRow = LRow
End If
Next ColCount

For RowCount = 1 To LastRow
LastCol = .Cells(RowCount, Columns.Count). _
End(xlToLeft).Column
If .Range("A" & RowCount) < "" Or _
LastCol 1 Then

.Rows(RowCount).Copy _
Destination:=Sheets("Sheet2").Rows(NewRow)
NewRow = NewRow + 1
End If
Next RowCount
End With
"Miree" wrote:

I have 8 columns of user entered data which i need to copy into another
worksheet.
I have the code to move it over but not all 8 colums will be filled all the
time and i dont want to copy over blank lines. I want to write code to say if
cell 1 is empty donot copy go to cell 2, then if cell 2 is empty, donot copy
goto cell 3..... and so on.
it may be that random colums have data so i need it to check each one.



All times are GMT +1. The time now is 01:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com