macro amendment (collation of data)

jaypatel

Active Member
Joined
Nov 25, 2002
Messages
389
Hi,

I have the following script (with help of mrexcel.com, thanks):

Sub test()

Dim strPath As String
Dim strFile As String
Dim wkbOpen As Workbook
Dim wksOpen As Worksheet
Dim wkbDest As Workbook
Dim wksDest As Worksheet
Dim NextRow As Long

Application.ScreenUpdating = False

Set wkbDest = ActiveWorkbook
Set wksDest = ActiveSheet

strPath = "C:\Documents and Settings\jpatel\My Documents\macro extraction"

If Right(strPath, 1) <> "\" Then strPath = strPath & "\"

strFile = Dir(strPath & "*.xls*")

With wksDest
NextRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With

Do While Len(strFile) > 0
If strFile <> wkbDest.Name Then
Set wkbOpen = Workbooks.Open(Filename:=strPath & strFile)
Set wksOpen = wkbOpen.Worksheets("sheet1") 'Change the sheet name accordingly
With wksOpen
.Cells(4, "c").Copy Destination:=wksDest.Cells(NextRow, "A")
.Cells(4, "d").Copy Destination:=wksDest.Cells(NextRow, "B")
.Cells(3, "g").Copy Destination:=wksDest.Cells(NextRow, "C")
wksDest.Cells(NextRow, "D").Value = .Cells(5, "c").Value
.Cells(4, "g").Copy Destination:=wksDest.Cells(NextRow, "e")
End With
wkbOpen.Close savechanges:=False
NextRow = NextRow + 1
End If
strFile = Dir
Loop

Application.ScreenUpdating = True

End Sub

but, i need to extract, certain cells in column c in column A, cells in column D in column B, cells in Column E in column C etc. ie Cell C4 in A1, cell C5 in A2, cell in C6 in A3, and correspondingly, Cell D4 in B1, Cell D5 in B2.

Can you help.

Regards

Jay
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Forum statistics

Threads
1,224,581
Messages
6,179,668
Members
452,936
Latest member
anamikabhargaw

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