Thread: VBA
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
ryguy7272 ryguy7272 is offline
external usenet poster
 
Posts: 2,836
Default VBA

Does this doe what you want?

Sub CopyToNewSheet()
Dim myrange, copyrange As Range
Sheets("Sheet1").Select

Set myrange = Range("A2:A10") '< -- Change to Suit your needs
For Each c In myrange
If c.Value = "X" Then
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If

End If
Next
copyrange.Copy

Sheets("Sheet2").Select

ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Select
ActiveCell.Offset(1, 0).Select

Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

End Sub

Before running the code, make a backup of your data!! You never know when a
new macro will do something you don't intend it to do!!

Good luck,
Ryan---
--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Renaes12" wrote:

I'm just learning VBA for work and was wondering how I could do something
like this.

Basically, when cell A2 = X in sheet1- I'd like to be able to populate
sheet2 with information from B2, C2, and D2. And then down the rows
appropriately (if A3=X, fill in B3, C3, D3). And not over filling current
information on sheet2(so finding the next empty row and filling in the new
information).

Thanks!