Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My bet is your recorded macro is still in a General module, but the
commandbutton2_click procedure is behind a worksheet. If you refer to an unqualified range in a general module, it means the range on the active sheet. But references to an unqualified range behind the worksheet refers to the sheet holding the code. Option Explicit Private Sub CommandButton2_Click() Dim Rng as range dim c as range with worksheets("Paid Recievables") set rng = .cells(.rows.count,1).end(xlup).offset(1,0) end with For Each c In Worksheets("ART Report").Range("P3:P10") If lcase(c.Value) = "p" Then c.EntireRow.Copy _ destination:=rng set rng = rng.offset(1,0) 'for row to copy end if Next End Sub And watch out. Some day you might fix the spelling of Recievables on the worksheet tab and your macro will break. I added some Dim statements, too. And changed the check to look for upper/lower case. Neal Miller wrote: ok here is my code it backs up a record to another sheet Private Sub CommandButton2_Click() For Each c In Worksheets("ART Report").Range("P3:P10") If c.Value = "p" Then c.EntireRow.Copy Sheets("Paid Recievables").Select Set rng = Cells(Rows.Count, 1).End(xlUp) Rows(rng.Row + 1).Select Selection.Insert Shift:=x1Down End If Next End Sub and the the macro I first created that works: Sub Pselect() ' ' Macro1 Macro ' Macro recorded 3/12/2003 by me ' For Each c In Worksheets("ART Report").Range("P1:P10") If c.Value = "p" Then c.EntireRow.Copy Sheets("Paid Recievables").Select Set rng = Cells(Rows.Count, 1).End(xlUp) Rows(rng.Row + 1).Select Selection.Insert Shift:=x1Down End If Next End Sub also I am trying to use this bit of code to set of the range of the for statement "Set rng = Cells(Rows.Count, 1).End(xlUp)" but have not got it to work as of yet? any help is greatly appreciated -- Dave Peterson |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
VBA macro runs fine, but freezes if I try to do ANYTHING else whileit runs | Setting up and Configuration of Excel | |||
vba code runs...need spaces ........ | Excel Discussion (Misc queries) | |||
One macro runs then it auto runs another macro | Excel Discussion (Misc queries) | |||
Can you code a macro so it runs multiple times in the same workboo | Excel Discussion (Misc queries) | |||
Code runs every other time | Excel Programming |