Select cell +2 in column to copy data in another cell

afc171

Board Regular
Joined
Jan 14, 2017
Messages
145
Office Version
  1. 2013
Platform
  1. Windows
Hi guys,

I have this VBA to select cell B3,C3 and D3 which copies to a column N5, N6 and N7

I would like to know how to select any cell in column B plus including the 2 cells next to it like above and copy these to the columns N5, N6 and N7

Code:
[COLOR=#011993][FONT=Menlo]Sub Cells()[/FONT][/COLOR][FONT=Menlo]
[/FONT]
[COLOR=#000000][FONT=Menlo][COLOR=#011993]Dim[/COLOR] CopyData [COLOR=#011993]As[/COLOR] Range[/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo][COLOR=#011993]Dim[/COLOR] cell [COLOR=#011993]As[/COLOR] Range[/FONT][/COLOR]
[COLOR=#011993][FONT=Menlo]Dim[COLOR=#000000] x [/COLOR]AsInteger[/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[COLOR=#000000][FONT=Menlo]x = 0[/FONT][/COLOR]
[COLOR=#011993][FONT=Menlo]Set CopyData = Range("[/FONT][/COLOR][COLOR=#011993][FONT=Menlo]B3, C3, D3[/FONT][/COLOR][COLOR=#011993][FONT=Menlo]")[/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[COLOR=#000000][FONT=Menlo][COLOR=#011993]For[/COLOR] [COLOR=#011993]Each[/COLOR] cell [COLOR=#011993]In[/COLOR] CopyData[/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo]    Range("N5").Offset(x) = cell.Value[/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo]    x = x + 1[/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo][COLOR=#011993]Next[/COLOR] cell[/FONT][/COLOR]
[FONT=Menlo]
[/FONT]
[COLOR=#011993][FONT=Menlo]EndSub[/FONT][/COLOR]

anyone help me out please?

Thanks you
 
If you don't want to transpose the data, just remove the Transpose function:

Code:
[COLOR=#000000][FONT=Menlo][COLOR=#011993]If[/COLOR] ActiveCell.Column = 2 [COLOR=#011993]Then[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo]        Range("B4:E4") = ActiveCell.Resize(, 4)[/FONT][/COLOR]
[COLOR=#011993][FONT=Menlo]EndIf[/FONT][/COLOR]
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
If you don't want to transpose the data, just remove the Transpose function:

Code:
[COLOR=#000000][FONT=Menlo][COLOR=#011993]If[/COLOR] ActiveCell.Column = 2 [COLOR=#011993]Then[/COLOR][/FONT][/COLOR]
[COLOR=#000000][FONT=Menlo]        Range("B4:E4") = ActiveCell.Resize(, 4)[/FONT][/COLOR]
[COLOR=#011993][FONT=Menlo]EndIf[/FONT][/COLOR]


hmm does not seem to put any data in the cells?
 
Upvote 0

Forum statistics

Threads
1,224,847
Messages
6,181,324
Members
453,032
Latest member
Pauh

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