LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Copy rows with values in sheet 1 to next empty row in sheet2

My interpretation here is that you want to include any rows where the column
A cell contains a value but not if it contains a Formula or Formatting. (I
interpretted the Formatting as Number formatting.)

If my interpretation is correct then try the following. I kept the If/EndIf
tests separate so they are easy to delete if you don't want some of the tests.

Sub CopyData()

Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rngColA As Range
Dim c As Range

Set ws1 = Sheets("Sheet1")
Set ws2 = Sheets("Sheet2")

With ws1
'Following assumes column headers and
'data starts on row 2.
Set rngColA = .Range(.Cells(2, "A"), _
.Cells(.Rows.Count, "A").End(xlUp))
End With

For Each c In rngColA
'Test if empty cell
If IsEmpty(c.Value) Then
GoTo endForEach 'Empty cell column A so skip
End If

'Test number format
If c.NumberFormat < "General" Then
GoTo endForEach 'Formatted so skip
End If

'Test for formula
If Left(c.Formula, 1) = "=" Then
GoTo endForEach 'Is formula so skip
End If

c.EntireRow.Copy
ws2.Cells(Rows.Count, "A") _
.End(xlUp).Offset(1, 0) _
.PasteSpecial Paste:=xlPasteValues

endForEach:
Next c
Application.CutCopyMode = False
ws2.Select
Range("A1").Select
End Sub


--
Regards,

OssieMac


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
copy data from sheet2 to sheet1 when sheet2 has variable # of rows Anne Excel Discussion (Misc queries) 6 February 27th 09 09:48 PM
adding rows, pasting values then empty sheet misscharliebrown Excel Worksheet Functions 2 October 30th 08 03:07 AM
how do copy "sheet1!A1+1 in sheet2 to sheet 3 and get "sheet2!A1+ Dany Excel Discussion (Misc queries) 5 April 16th 07 03:27 AM
How to Check Empty Rows in Sheet2 when sheet1 buton clicked bernardng[_4_] Excel Programming 2 May 22nd 06 12:00 PM
Need help coping a range of data from sheet 1 to the next empty cell in sheet2 [email protected] Excel Programming 3 April 27th 06 09:31 PM


All times are GMT +1. The time now is 06:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"