VBA copy data from 1 excel to another - changing range

zardia

New Member
Joined
Aug 7, 2019
Messages
9
Hi all,

I got this macro working where I will copy and paste datafrom 1 excel to another.

What it does is that it will copy data from a predefinedrange from source file then paste it into the predefined range of thedestination file, then repeat. Each time it repeats, the range from the sourcefile will move 2 columns to the right, while the destination file will move 4columns to the right.
Therefore I used the char(67) to set (starting from Col C)and then + 2 for source file and + 4 for destination file for each loop.
But the problem is that it will die when it reaches AA.


Anyone got any ideas? Thanks

Rich (BB code):
Sub ExtractFromInput()


 


 


'daily input file, range 2 cols x 20 rows, then paste intodaily performance range 2 x 20


'each loop, daily input file cols +2, performance + 4


 


 


 


Dim WkBk_Active As Workbook


Dim Rng_Active As Range


Dim WkBk_Input As Workbook


Dim Rng_Input As Range


Dim FName As String


Dim FPath As String


 


  


 


    Set WkBk_Active =Application.ActiveWorkbook


    FPath =WkBk_Active.Worksheets("Menu").Range("B1")


    FName =WkBk_Active.Worksheets("Menu").Range("B2")


    Set WkBk_Input =Application.Workbooks.Open(FPath & "\" & FName)


    


    'set the variableof the range col of the input file and performance file for loop


    ColC = 67


    ColD = 68


    'Set the jumpvalue to 0 to start off


    InputJump = 0


    PerfJump = 0


   


    'loop from inputfile and paste into performance file


    For j = 1 To 31


    


    'for Input day =13-25, Col need to add A in front, for 26+, Col add B in front.


 


    


    Set Rng_Input =WkBk_Input.Worksheets("Alex").Range(Chr(ColC + InputJump) & 3& ":" & Chr(ColD + InputJump) & 22)


    Set Rng_Active =WkBk_Active.Worksheets("Alex").Range(Chr(ColC + PerfJump) & 3& ":" & Chr(ColD + PerfJump) & 22)


    Rng_Input.CopyRng_Active


        


    


    


    


    Next j


    


End Sub







 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
ps.... after which I want to repeat this on all sheets that are in a list in a worksheet call SheetName (A:A)
 
Upvote 0
I managed to get the first part working, but if anyone can teach me how to run this macro on all designated sheets that would be great, thanks!

In the same workbook, I have a sheet called SheetName, which contains a list of sheetnames (same workbook) that I need to run this macro on.
(the list gets amended occasionally, so I cannot hardcode the sheetnames in the macro)
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,973
Members
452,540
Latest member
haasro02

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