Working with the current selection

  • Thread starter Thread starter Keith Wilby
  • Start date Start date
K

Keith Wilby

Bit of a newbie question here.

I've written a bit of VBA that I want to work over whatever column of cells
I have selected. For example, I might want to run it on A1 to A8 but on
another occasion I might want it to run on A9 to A20. I currently input the
range via input boxes, could anyone advise on the syntax I should use to use
the currently selected cells?

Many thanks.
 
Keith Wilby said:
Bit of a newbie question here.

I've written a bit of VBA that I want to work over whatever column of
cells I have selected. For example, I might want to run it on A1 to A8
but on another occasion I might want it to run on A9 to A20. I currently
input the range via input boxes, could anyone advise on the syntax I
should use to use the currently selected cells?

Many thanks.

Sorry, here's my code:

Sub libTotals()

Dim intFirstCell As Integer, intLastCell As Integer, intPeriodCode As
Integer

intFirstCell = InputBox("What's the first row number?", "Enter first row
number")
intLastCell = InputBox("What's the last row number?", "Enter last row
number")
intPeriodCode = InputBox("What's the period code?", "Enter the period code")

Dim n As Integer, lngTotal As Long
n = intFirstCell - 1

Do Until n = intLastCell
n = n + 1
Cells(n, 10).Select
If Cells(n, 10).Value = intPeriodCode Then
lngTotal = lngTotal + Cells(n, 7)
End If
Loop

MsgBox lngTotal

End Sub
 
Back
Top