VBA Macro to copy non-adjacent cells to a different workbook

Ziad92

New Member
Joined
May 25, 2021
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am currently working on an integrated set of workbooks, where I need to transfer data values between workbooks. In order to do so I need a VBA Macro that can copy non-adjacent cells (ex. the locations of the cells are J4, J8, J12, J16....etc) and insert it in the other workbook with a different structure (ex. the space between the cells would be 4 instead of 3.)

This is my first time using VBA so I'm not sure if it's possible. I'm using Microsoft 365.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
You haven't specified which workbook or worksheets, so here is some code to copy from the active worksheet to "sheet2"
You haven't specifed what range you wnat to do this for so I guessed 32 rows
You can alter the interval between the cells by chaning the steps for the I loop and the increment for Y step
VBA Code:
Sub test()
inarr = Range("A1:W32")
 With Worksheets("sheet2")
  y = 3
  For i = 4 To 32 Step 4
    .Range(.Cells(y, 10), .Cells(y, 10)) = inarr(i, 10)
    y = y + 3
 Next i
End With
End Sub
 
Upvote 0
As wild cross posting was not specified as well …​
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: VBA Macro to copy non-adjacent cells to a different workbook
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,126
Members
453,021
Latest member
Justyna P

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