Hello,
I've been trying to figure out how to select a range based on the last column and last row of data.
I need a code that will look for the word "Technology' in column L. Once it finds that word, I need it to select all data from column A to P. Copy that data and paste it into cell K22 of Sheet2. For example, range A27:P52 would be selected, but it the location of this range varies which is why I want to select range from first instance of the word technology to the last between columns A and P.
This is the code I have so far, but I am getting an error message "Method 'Range' of object '_Global' failed" in the "Range("rangex").Copy line of the code.
What did I do wrong?
I've been trying to figure out how to select a range based on the last column and last row of data.
I need a code that will look for the word "Technology' in column L. Once it finds that word, I need it to select all data from column A to P. Copy that data and paste it into cell K22 of Sheet2. For example, range A27:P52 would be selected, but it the location of this range varies which is why I want to select range from first instance of the word technology to the last between columns A and P.
This is the code I have so far, but I am getting an error message "Method 'Range' of object '_Global' failed" in the "Range("rangex").Copy line of the code.
What did I do wrong?
Code:
Sub CopyTechnology()
Dim LRow As Long, iRow As Long
Dim LastCol As Long
Dim rangex As Range
With Worksheets("Sheet1")
LastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
LRow = .Cells(.Rows.Count, "L").End(xlUp).Row
rangex = .Cells(LRow, 1).Resize(, LastCol)
For iRow = LRow To 1 Step -1
If .Cells(iRow, "L").Value = "Technology" Then
Range("rangex").Copy
End If
Next iRow
End With
End Sub