Home |
Search |
Today's Posts |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dave,
Here's some code that does most of what you want. The trick is to know when you have not found the item, which is shown here. This code assumes a few things - that the range being searched is A1:A100 - that the value being searched for is 1 - that the worksheets are called Sheet1 and Sheet2 All of these can be modified up-front in the code. Dim oWS1 As Worksheet Dim oWs2 As Worksheet Dim cLastRow As Long Dim oCell As Range Dim myValue Dim myRange As Range myValue = 1 Set oWS1 = Worksheets("Sheet1") Set oWs2 = Worksheets("Sheet2") Set myRange = oWS1.Range("A1:A100") cLastRow = oWs2.Cells(Rows.Count, "A").End(xlUp).Row If cLastRow = 1 And oWs2.Cells(cLastRow, "A") = "" Then cLastRow = 0 End If Set oCell = myRange.Find(myValue) If Not oCell Is Nothing Then Do Until oCell Is Nothing cLastRow = cLastRow + 1 oCell.EntireRow.Cut Destination:=oWs2.Cells(cLastRow, "A") Set oCell = myRange.FindNext Loop End If -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "dave" wrote in message ... I've been a programmer for many years. I can do the programming if I can figure out how to get at the data. That's my problem with using VBA with Excel (or Word, etc.) How do I find out how to access a cell, group of cells, range, worksheet, etc. using VBA. For example, I have a worksheet that has rows of data. I would like to search a column for a particular value and if it is present, delete the data and row from the current worksheet and paste it into another sheet. I can figure out how to search for the data by recording a macro when I do it manually. But when I then select the row to so I can do a Ctrl-X to "move" the data, the recorded macro does a .Select on that specific row. I need to be able to have the selected row number put into a variable that I can use to "cut" the data then when I go to the target sheet I need to have the target row incremented. Then I want to go back to the source sheet, delete the row and repeat process until the search is no longer successful. How do I do those kind of things? I'm not real familiar with the data setup that allows me access to the features I need. Thanks for any and all help, dave |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Very basic VBA question. | Excel Discussion (Misc queries) | |||
basic question | New Users to Excel | |||
Basic question...sorry | Excel Worksheet Functions | |||
Basic question | Excel Discussion (Misc queries) | |||
Basic VBA question | Excel Programming |