ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA (https://www.excelbanter.com/excel-programming/426259-vba.html)

Renaes12

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!

ryguy7272

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!



All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com