View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Auric__ Auric__ is offline
external usenet poster
 
Posts: 538
Default Input, copy, new book?

JonathanK1 wrote:

I have a macro that prompts an input:

Dim TheAnswer$
TheAnswer = Inputbox(

Etc. etc. You get the gist. Anyway, it takes the input but doesn't do
anything with it. I have one colmn in the spreadsheet that has offices
(e.g., Texas, Ohio etc.). Its column H. I'd like the input to grab the
rows that have the input I provide and past them into a new
book/spreadsheet. Is this possible?

So, there may be twenty rows with Texas mixed in. I want all of these
pasted into the new spreadsheet. So when I click the button it'll ask
me for the input. I enter Texas and it gives me all the rows with Texas
in the new book/spreadsheet. Sorry if I'm overexplaining.


Here's a 5-minute hack; see if it works for you:

Sub copier()
Dim TheAnswer As String
Dim working As Worksheet, dumping As Workbook
Set working = ActiveSheet
TheAnswer = LCase$(InputBox("State?"))
Set dumping = Workbooks.Add
For x = 1 To working.Cells.SpecialCells(xlCellTypeLastCell).Row
If LCase$(working.Cells(x, 8).Value) = TheAnswer Then
working.Rows(x).EntireRow.Copy
dumping.Activate
ActiveSheet.Paste
ActiveCell.Offset(1).Select
End If
Next
Application.CutCopyMode = False
End Sub

--
This is why my characters usually end up being impossible for me to like:
My curiosity leads them into actions I can't condone.