VBA-going to the column that is specified in a cell

BoosBoo

New Member
Joined
Dec 30, 2015
Messages
2
I don't know VBA much at all.... and I need help.
I'm trying to code it so that I can go to the column that I specify in a cell.
In cell A5, I have 32. so I want to select the entire column of AF and copy and paste that column to the right, so in this case, column AG.

next month, it will be 33 in cell A5, so I don't want to use the column letter like AF.

And after copying the whole column 32 to 33, I want to copy cell AE5: AE10 ( so 1 minus of what it shows in cell A5, but the rows are always 5 to 10) to AF5:AF10 (one to the right)

Thank you!!!!
 

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
I don't know VBA much at all.... and I need help.
I'm trying to code it so that I can go to the column that I specify in a cell.
In cell A5, I have 32. so I want to select the entire column of AF and copy and paste that column to the right, so in this case, column AG.

next month, it will be 33 in cell A5, so I don't want to use the column letter like AF.

And after copying the whole column 32 to 33, I want to copy cell AE5: AE10 ( so 1 minus of what it shows in cell A5, but the rows are always 5 to 10) to AF5:AF10 (one to the right)

Thank you!!!!
Hi BoosBoo, welcome to the boards.

Try out the following macro in a COPY of your workbook. The following code is added to a standard module and applied to a button to be run:

Rich (BB code):
Sub CopyRanges()
' Define variable
Dim ColNo As Integer
' Defines variable ColNo as the value of cell A5
ColNo = Range("A5").Value
' Select the entire column based on the value in A5
Range(Cells(, ColNo), Cells(, ColNo)).EntireColumn.Select
' Copy selection and paste 1 column over to the right
Selection.Copy Destination:=Selection.Offset(0, 1)
' Select rows 5:10 of 1 column to the left of pre-existing selection
Range(Cells(5, ColNo - 1), Cells(10, ColNo - 1)).Select
' Copy new selection and paste 1 column over to the right
Selection.Copy Destination:=Selection.Offset(0, 1)
End Sub
 
Upvote 0
Hi BoosBoo, welcome to the boards.

Try out the following macro in a COPY of your workbook. The following code is added to a standard module and applied to a button to be run:

Rich (BB code):
Sub CopyRanges()
' Define variable
Dim ColNo As Integer
' Defines variable ColNo as the value of cell A5
ColNo = Range("A5").Value
' Select the entire column based on the value in A5
Range(Cells(, ColNo), Cells(, ColNo)).EntireColumn.Select
' Copy selection and paste 1 column over to the right
Selection.Copy Destination:=Selection.Offset(0, 1)
' Select rows 5:10 of 1 column to the left of pre-existing selection
Range(Cells(5, ColNo - 1), Cells(10, ColNo - 1)).Select
' Copy new selection and paste 1 column over to the right
Selection.Copy Destination:=Selection.Offset(0, 1)
End Sub


Fishboy!
Thank you so much! It worked perfectly!!
You're the best! have a nice day! :)
 
Upvote 0

Forum statistics

Threads
1,226,729
Messages
6,192,696
Members
453,747
Latest member
tylerhyatt04

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