View Single Post
  #16   Report Post  
Posted to microsoft.public.excel.programming
KelliInCali KelliInCali is offline
external usenet poster
 
Posts: 37
Default Help with Visual Basic for Excel

Thanks! Is a destination required or did you just throw that in for
convenience? I will actually be pasting values only to somewhere else
entirely. Will it mess it up to remove the destRng references? -kelli


"Norman Jones" wrote:

Hi Kelli,

Try:
'================
Public Sub Tester3()
Dim WB As Workbook
Dim SH As Worksheet
Dim FirstCell As Range
Dim LastCell As Range
Dim destRng As Range

Set WB = ActiveWorkbook '<<== CHANGE
Set SH = WB.Sheets("Sheet1") '<<== CHANGE

Set destRng = WB.Sheets("Sheet2").Range("A1") '<<== CHANGE

If Not IsEmpty(SH.Range("B1")) Then
Set FirstCell = SH.Range("B1")
Else
Set FirstCell = SH.Range("B1").End(xlDown)
End If

Set LastCell = SH.Cells(Rows.Count, "B").End(xlUp)

SH.Range(FirstCell, LastCell).Copy Destination:=destRng

End Sub
'<<================

Change the destRng to suit your requirements.

If the header row is not to be copied, change B1 to B2.


---
Regards,
Norman



"KelliInCali" wrote in message
...
Norman... If it's not too presumptuous of me, may I ask one more favor? I
now just need to select and copy all rows for which B is populated. At
this
point, all the records with data in B are grouped and there are no empty
rows
after the last record. You've been great and I really appreciate the
help!
-kelli