VBA coding data import/export within Excel

Pezmerga

New Member
Joined
Jan 15, 2015
Messages
2
Dear Excel and VBA experts,
As of recently I have compiled a piece of VBA coding and I could use some fine tuning in it. Perhaps some help can be provided here. I’ll further explain the case and my vision on how I would like to have it work.

Case:
I have one source spreadsheet in which there are an undefined number of columns. These columns should contain the data of around 15-50 target spreadsheets. The target spreadsheets have a certain CONSISTENT (they are all the same) lay-out to make them quite easy to fill in and read.
In the end each of the target spreadsheets should have the data filled in their own column in the source spreadsheet. The current code does this perfectly well, except for one problem. It fills it in a single column and overwrites this column when the next file is opened/selected.

Vision:
I would like that the VBA recognizes that the, in the code, D column is full and uses the E and at the selection of the third document the F column or either a selection in which I could tell, before the import of information begins, which column should be used.

I would like to thank you in advance for helping me.
Best regards,
Pezmerga


Code:
Sub test()
    Dim wb As Workbook
    Dim wb2 As Workbook
    Dim ws As Worksheet
    Dim vFile As Variant

    Set wb = ActiveWorkbook
    vFile = Application.GetOpenFilename("Excel-files,*.xl??", _
        1, "Select One File To Open", , False)
    If TypeName(vFile) = "Boolean" Then Exit Sub
    Workbooks.Open vFile
    Set wb2 = ActiveWorkbook

    wb.Worksheets(“Sheet1”).Range("D13").Value = wb2.Worksheets(“Sheet1”).Range("E14").Value '1
    wb.Worksheets(“Sheet1”).Range("D14").Value = wb2.Worksheets(“Sheet1”).Range("E15").Value '2
    wb.Worksheets(“Sheet1”).Range("D16").Value = wb2.Worksheets(“Sheet1”).Range("E18").Value '3
    wb.Worksheets(“Sheet1”).Range("D17").Value = wb2.Worksheets(“Sheet1”).Range("E19").Value '4
    wb.Worksheets(“Sheet1”).Range("D18").Value = wb2.Worksheets(“Sheet1”).Range("E20").Value '5
    wb.Worksheets(“Sheet1”).Range("D22").Value = wb2.Worksheets(“Sheet1”).Range("E25").Value '6
    wb.Worksheets(“Sheet1”).Range("D23").Value = wb2.Worksheets(“Sheet1”).Range("E26").Value '7
    wb.Worksheets(“Sheet1”).Range("D27").Value = wb2.Worksheets(“Sheet1”).Range("E31").Value '8
    wb.Worksheets(“Sheet1”).Range("D28").Value = wb2.Worksheets(“Sheet1”).Range("E32").Value '9
    wb.Worksheets(“Sheet1”).Range("D29").Value = wb2.Worksheets(“Sheet1”).Range("E33").Value '10
    wb.Worksheets(“Sheet1”).Range("D37").Value = wb2.Worksheets(“Sheet1”).Range("E37").Value '11
    wb.Worksheets(“Sheet1”).Range("D38").Value = wb2.Worksheets(“Sheet1”).Range("E38").Value '12
    wb.Worksheets(“Sheet1”).Range("D39").Value = wb2.Worksheets(“Sheet1”).Range("E39").Value '13
    wb.Worksheets(“Sheet1”).Range("D47").Value = wb2.Worksheets(“Sheet1”).Range("E43").Value '14
    wb.Worksheets(“Sheet1”).Range("D53").Value = wb2.Worksheets(“Sheet1”).Range("G45").Value '15
    wb.Worksheets(“Sheet1”).Range("D58").Value = wb2.Worksheets(“Sheet1”).Range("G46").Value '16
    wb.Worksheets(“Sheet1”).Range("D63").Value = wb2.Worksheets(“Sheet1”).Range("G47").Value '17
    wb.Worksheets(“Sheet1”).Range("D68").Value = wb2.Worksheets(“Sheet1”).Range("G49").Value '18
    wb.Worksheets(“Sheet1”).Range("D73").Value = wb2.Worksheets(“Sheet1”).Range("G50").Value '19
    wb.Worksheets(“Sheet1”).Range("D78").Value = wb2.Worksheets(“Sheet1”).Range("G51").Value '20
    wb.Worksheets(“Sheet1”).Range("D83").Value = wb2.Worksheets(“Sheet1”).Range("G53").Value '21
    wb.Worksheets(“Sheet1”).Range("D117").Value = wb2.Worksheets(“Sheet1”).Range("E70").Value '22
    wb.Worksheets(“Sheet1”).Range("D118").Value = wb2.Worksheets(“Sheet1”).Range("E71").Value '23
    wb.Worksheets(“Sheet1”).Range("D125").Value = wb2.Worksheets(“Sheet1”).Range("E73").Value '24
    wb.Worksheets(“Sheet1”).Range("D131").Value = wb2.Worksheets(“Sheet1”).Range("E74").Value '25
    wb.Worksheets(“Sheet1”).Range("D132").Value = wb2.Worksheets(“Sheet1”).Range("E75").Value '26
    wb.Worksheets(“Sheet1”).Range("D151").Value = wb2.Worksheets(“Sheet1”).Range("E82").Value '27
  
wb2.Close savechanges:=False
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Okay I can simplify the problem now, the ranges D13, D14, etc has to turn into range E13, E14 and so on. I hope someone out there now knows how/what to do?
 
Upvote 0

Forum statistics

Threads
1,217,153
Messages
6,134,928
Members
449,897
Latest member
andrew3650

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