#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA

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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
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!

Reply
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



All times are GMT +1. The time now is 10:56 AM.

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

About Us

"It's about Microsoft Excel"