Hi! I have created the following macro in Excel to do the following. But I need to add a function to it to return certain columns of data based on a certain name that is placed in column c. The following macro lets me search for a particular number in column A and return those rows and copy them on another sheet.
Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim LSearchValue As String
On Error GoTo Err_Execute
LSearchValue = InputBox("Please enter a value to search for.", "Enter value")
'Start search in row 4
LSearchRow = 4
'Start copying data to row 16 in Sheet2 (row counter variable)
LCopyToRow = 16
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column A = LSearchValue,copy entire row to Sheet2
If Range("A" & CStr(LSearchRow)).Value = LSearchValue Then
'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets("Sheet2").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Sheet1 to continue searching
Sheets("Sheet1").Select
End If
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
MsgBox "All matching data has been copied."
Exit Sub
Err_Execute:
MsgBox "An error occurred."
End Sub
Spool# | Reading No | Alloy1 | Mo | Nb | W | Cu | Ni | Fe | Cr | V | Ti | Al |
1111 | 1 | SS-304 : 0.31 | 0.125 | 0.01 | 0 | 0.159 | 10.385 | 66.759 | 19.778 | 0.178 | 0 | 0 |
1111 | 2 | SS-304 : 1.09 | 0.032 | 0 | 0 | 0 | 10.68 | 66.942 | 19.617 | 0.263 | 0 | 0 |
2222 | 4 | P11 : 0.11 | 0.022 | 0 | 0 | 0 | 10.09 | 69.191 | 18.781 | 0.2 | 0 | 0 |
2222 | 5 | P11 : 0.82 | 0.141 | 0 | 0 | 0 | 10.496 | 67.684 | 19.659 | 0 | 0 | 0 |
2222 | 6 | P11 : 1.20 | 0.034 | 0 | 0 | 0 | 9.486 | 68.106 | 20.256 | 0 | 0 | 0 |
3333 | 7 | CS : 1.56 | 0.078 | 0 | 0 | 0.219 | 10.987 | 66.068 | 19.643 | 0.155 | 0 | 0 |
3333 | 8 | CS : 0.62 | 0.099 | 0 | 0 | 0.279 | 9.529 | 67.261 | 19.861 | 0 | 0 | 0 |
3333 | 9 | CS: 0.16 | 0.089 | 0 | 0 | 0 | 9.358 | 69.928 | 19.244 | 0 | 0 | 0 |
3333 | 10 | CS: 1.37 | 0.051 | 0 | 0 | 0 | 10.355 | 66.989 | 20.284 | 0 | 0 | 0 |
I am downloading this information out of a piece of equipment we have that makes readings on pipe. I convert the information into excel and drop it on sheet1. I then have a report on sheet2 that it copies the search information into Row16 for each search I perform. I need to be able to do this over and over again so I can just print the report. I need the info for each search to clear on Row 16 before the next search Is performed. I am not saving each report by spool#. I need to assign only certain columns to each different name in column C. Example for SS-304 pull only column headings and their data Mo,Cu,Ni and Cr andP11 pull only column headings and their data W,V&Ti. I need it do this then copy the information to sheet1 on Row 16. Also, I need it to separate the data in Column C and remove the : if possible. This information pulls into the column combined and I need just the text data in one column and the decimal in another.
I don't even know if what I need is even possible. But I really need this ASAP because we are starting to use the equipment and I really need a working report to drop the data into.
Thanks!