Hello,
I am a beginner at Macros.
I want to find the text "T+1" in column C , and in that same row , copy values of cells in columns I-L to another spreadsheet .
So if it finds "T+1" in cell C20, i want to copy the values of cells I20:L20 into another workbook.
I found a way to do it one by one, but I have to believe there is a way to do it using a range.
Here is what i have that works, but I am wondering if there is a better way. I'd appreciate any suggestions.
Thank You
Sub Get Data
Dim nPath As String
Dim fileNameString As String
Dim fileName As String
nPath = "\\Swib\root\ShrInvOper\Fund Accounting\Reporting\InvestOne\"
fileNameString = Format(Date, "dd-mmm-yyyy") & " 1 SIF Holding Detail by Maturity Date" & ".xls"
fileName = Dir(nPath & fileNameString)
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim a As Long
For a = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(a, "C").Value = "T+1" Then
Cells(a, "I").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("D7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End If
Next
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim b As Long
For b = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(b, "C").Value = "T+1" Then
Cells(b, "J").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("E7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
Next
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim c As Long
For c = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(c, "C").Value = "T+1" Then
Cells(c, "K").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("F7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
Next
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim d As Long
For d = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(d, "C").Value = "T+1" Then
Cells(d, "L").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("G7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
Next
Range("D7").Select
Application.CutCopyMode = False
Workbooks(fileName).Close
End Sub
I am a beginner at Macros.
I want to find the text "T+1" in column C , and in that same row , copy values of cells in columns I-L to another spreadsheet .
So if it finds "T+1" in cell C20, i want to copy the values of cells I20:L20 into another workbook.
I found a way to do it one by one, but I have to believe there is a way to do it using a range.
Here is what i have that works, but I am wondering if there is a better way. I'd appreciate any suggestions.
Thank You
Sub Get Data
Dim nPath As String
Dim fileNameString As String
Dim fileName As String
nPath = "\\Swib\root\ShrInvOper\Fund Accounting\Reporting\InvestOne\"
fileNameString = Format(Date, "dd-mmm-yyyy") & " 1 SIF Holding Detail by Maturity Date" & ".xls"
fileName = Dir(nPath & fileNameString)
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim a As Long
For a = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(a, "C").Value = "T+1" Then
Cells(a, "I").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("D7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
End If
Next
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim b As Long
For b = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(b, "C").Value = "T+1" Then
Cells(b, "J").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("E7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
Next
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim c As Long
For c = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(c, "C").Value = "T+1" Then
Cells(c, "K").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("F7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
Next
Workbooks.Open nPath & fileName
Sheets("Main").Select
Dim d As Long
For d = 2 To ActiveSheet.UsedRange.Rows.Count
If Cells(d, "C").Value = "T+1" Then
Cells(d, "L").Copy
ThisWorkbook.Activate
ActiveSheet.Select
Range("G7").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
End If
Next
Range("D7").Select
Application.CutCopyMode = False
Workbooks(fileName).Close
End Sub