View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Melanie Breden Melanie Breden is offline
external usenet poster
 
Posts: 88
Default Search a column for the last five cells?

Hi Daniel,

Daniel wrote:
I need to search 1 column ( say A ) and find the last cell. From there
i want to step five cells back, copy every value for each on and paste
them into a specific textbox i have in a userform.


if I understand you correctly, are the 5 last values of the column A to be
transferred into *one* textbox?
Place the MultiSelect-characteristic of the textbox on True,
in order to arrange the values one below the other:

Private Sub CommandButton1_Click()
Dim lngRow As Long
Dim rngArea As Range
Dim intI As Integer

lngRow = Worksheets(1).Cells(Rows.Count, "A").End(xlUp).Row - 4
Set rngArea = Worksheets(1).Cells(lngRow, "A").Resize(5, 1)

For intI = 1 To rngArea.Cells.Count
TextBox1.Text = TextBox1.Text & IIf(TextBox1.Text = "", "", vbCr) _
& rngArea.Cells(intI)
Next intI
End Sub

--
Mit freundlichen Grüssen

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)