View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Neal Miller Neal Miller is offline
external usenet poster
 
Posts: 4
Default Code runs different in a commandbutton than a macro why?


Dav

I actually want to insert this row into the Paid Receivables work sheet and I want to pasrse the Art Report sheet to determine the range. I will post my effort toward this shortly I hope

Neal
----- Dave Peterson wrote: ----

My bet is your recorded macro is still in a General module, but th
commandbutton2_click procedure is behind a worksheet

If you refer to an unqualified range in a general module, it means the range o
the active sheet. But references to an unqualified range behind the workshee
refers to the sheet holding the code

Option Explici
Private Sub CommandButton2_Click(

Dim Rng as range
dim c as rang

with worksheets("Paid Recievables"
set rng = .cells(.rows.count,1).end(xlup).offset(1,0
end wit

For Each c In Worksheets("ART Report").Range("P3:P10"
If lcase(c.Value) = "p" The
c.EntireRow.Copy
destination:=rn
set rng = rng.offset(1,0) 'for row to cop
end i
Nex

End Su

And watch out. Some day you might fix the spelling of Recievables on th
worksheet tab and your macro will break

I added some Dim statements, too. And changed the check to look for upper/lowe
case

Neal Miller wrote
ok here is my code it backs up a record to another shee
Private Sub CommandButton2_Click(
For Each c In Worksheets("ART Report").Range("P3:P10"

If c.Value = "p" The
c.EntireRow.Cop
Sheets("Paid Recievables").Selec
Set rng = Cells(Rows.Count, 1).End(xlUp
Rows(rng.Row + 1).Selec
Selection.Insert Shift:=x1Dow
End I
Nex
End Su
and the the macro I first created that works
Sub Pselect(


' Macro1 Macr
' Macro recorded 3/12/2003 by m

For Each c In Worksheets("ART Report").Range("P1:P10"
If c.Value = "p" The
c.EntireRow.Cop
Sheets("Paid Recievables").Selec
Set rng = Cells(Rows.Count, 1).End(xlUp
Rows(rng.Row + 1).Selec
Selection.Insert Shift:=x1Dow
End I
Nex
End Su
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 appreciate


--

Dave Peterso