Thread: Macro basics
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Dallman Ross Dallman Ross is offline
external usenet poster
 
Posts: 390
Default Macro basics

In , Dave Peterson
helped me out by fixing up my code some:

Dim iLastCol As Long
dim iLastRow as long

With Worksheets("2006 Realized Gains")
'you have to select the sheet before you can select a range
'but you don't have to select either to get your code to work
'.select
'.Cells.Select
.cells.EntireColumn.Hidden = False
.AutoFilterMode = False

iLastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
iLastRow = .cells(.rows.count,"A").end(xlup).row

application.goto _
reference:=.cells(ilastrow + 1, ilastcol) ',scroll:=true

end with


Thanks, Dave! That's much better.
A couple more questions: I used "Long" as the var type, and I
chose that because you'd done so earlier (in another thread where
you helped me). But why are we doing that? Why not Integer type?

I used column A to find the nextrow (iLastRow + 1) to go to.


Okay. I don't know if I need the application.goto stuff or not,
but after lots of experimentation recording macros and inspecting
the code and trying to bend it to my needs, I'd come up with that.
Actually, I took the "+ 1" back out, because my next line
in my macros is:

Range(Selection, "A1").Sort _
Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes

Maybe there's a better way to invoke that range for the sort.

I don't understand the second question.


The second question was how I can keep the value of the
goto reference so I don't have to repeat

application.goto _
reference:=.cells(ilastrow, ilastcol)

a bunch of times when I do other things later in the macro.

Probably if I knew more I wouldn't be using goto anyway,
so the question wouldn't be needed. But I don't know
other ways to set ranges for actions yet.

The next thing I want to do, for example, is move the row
defined as "iLastRow + 1" down X number of lines, where
X is determied by the number of rows in another sheet that
I've just refreshed data for. (The row I'm moving is a
row of totals and other calculated fields.)

(Then I'll want to fill the rows I've just inserted down to
the new location of my bottom, totals, row.)

================================================== ============
Dallman Ross wrote:

I'm trying to develop some macros. I'm not that versed
at it yet. Here is part of something:

Dim iLastCol As Long

With Worksheets("2006 Realized Gains")
Cells.Select
Selection.EntireColumn.Hidden = False
.AutoFilterMode = False

iLastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column

Application.Goto Reference:= _
"INDEX(R1:R65536,COUNTA(C[1])-1,30)"

See that "30" in the last line? That's Column 30 ("AD"). I
tried to use my "iLastCol" variable instead, but could
not. I tried all sorts of permutations; still no luck.
What's the trick?

Seconds question: How can I save the Application.Goto Reference
for repeat use without inserting that statement again each time?

E.g., later I will want to select the row below that
row. How would I do that?

Thanks for any help.
Dallman Ross