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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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