Reputation: 25
Currently I am working on making a macro that needs does the following things.
1) It looks through the top row, returning a named column
2) It then selects this column
3) Then it loops through column looking for the first value greater than zero.
4) I then take the row value of this "first" instance
5) From my public variables, I get a column value (#'s)
6) I combine the row value and column value to find my "data point"
Finally I want copy this value to another worksheet in the same workbook called "Critical Signals"
This is where I'm having trouble. Everytime I run my code I get a error "1004". I can't seem to copy and paste my selected cell to my second worksheet. Any ideas?
Sub Locate_Start_Of_Test()
'Use the Find Method to identify signal columns
Dim SigCol As Integer
Dim SigRow As Integer
Dim Cell As Range
Dim CritRow As Integer
'Variables to hold critical point of Start of Test
SigRow = 1 'Row Location of Signal Names
SigCol = Sheet1.Cells(SigRow, 1).EntireRow.Find(What:="EngAout_N_Actl (rpm)", LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext).Column
'SigCol now holds the value of rpm column
Columns(SigCol).Select
CritRow = 1
For Each Cell In Selection
If Cell.Value > 0 And Cell.Value <> "EngAout_N_Actl (rpm)" Then
Exit For
End If
CritRow = CritRow + 1
Next Cell
Sheets(1).Range(Cells(CritRow, Trip_point)).Copy
Sheets("Critical Signals").Activate
Range("E4").Select
ActiveSheet.Paste
End Sub
Upvotes: 1
Views: 3185
Reputation: 31364
You are close, simply remove Range
from this line:
Sheets(1).Range(Cells(CritRow, Trip_point)).Copy
So that it looks like this:
Sheets(1).Cells(CritRow, Trip_point).Copy
Also, I'd recommend not using Active
or Select
statements. For example your 4 lines of code to copy and paste could look like this instead:
Sheets("Critical Signals").Range("E4") = Sheets(1).Cells(CritRow, Trip_point)
Upvotes: 2