Excel VBA to find cell and select range

ash060200

New Member
Joined
Oct 12, 2017
Messages
2
Hi,
I am trying to create a macro that will select a cell using the find feature and then using that cell as the first cell for a range. I can use the find feature to select a cell and use that cell to either select the last cell in that column or the last cell in that row but not both. I need to select the last cell in both the row and the column.
I am not having much luck and would appreciate any help.

Dim lngLastRow As Long
Dim lngLastCol As Long


With Worksheets("Sheet1").Cells
Set mc = .Find("member id", After:=.Range("A2"), LookIn:=xlValues)
If Not mc Is Nothing Then
mc.Select
End If
End With


mc.Select

Range(ActiveCell, ActiveCell.End(xlToRight), ActiveCell.End(x1Down)).Select
Selection.Copy



** I have also tried this line but it does not like the variable starting cell.
Range("mc: " & strLastCol & lngLastRow).SpecialCells(xlCellTypeVisible).Select
Selection.Copy
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Hi. Try:

Code:
Sub test()
 Dim lngLastRow As Long
 Dim lngLastCol As Long
 Dim mc As Range
  With Worksheets("Sheet1").Cells
   Set mc = .Find("member id", After:=.Range("A2"), LookIn:=xlValues)
    If Not mc Is Nothing Then
     lngLastRow = .Cells(Rows.Count, mc.Column).End(xlUp).Row
     lngLastCol = .Cells(mc.Row, Columns.Count).End(xlToLeft).Column
     .Range(mc, Cells(lngLastRow, lngLastCol)).Copy
   End If
  End With
End Sub
 
Upvote 0
Thank you so much for the information. I did find another post that showed how to put it all in one line using Range(ActiveCell, Cells(ActiveCell.End(xlDown).Row, ActiveCell.End(xlToRight).Column)).Select.

I am glad to see your response to know what I missed. This forum is a great resource and a lot of information. Thank you again.
 
Upvote 0

Forum statistics

Threads
1,215,053
Messages
6,122,888
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top