VBA

  • Thread starter Thread starter Renaes12
  • Start date Start date
R

Renaes12

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!
 
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---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top