VBA code to loop and copy column values

PB7

Board Regular
Joined
Mar 1, 2011
Messages
58
Hello all,

I need to loop through a column and copy paste the text string contents 24 columns to the right in this spreadsheet.

This code loops, but I can not figure out how to copy/paste the exact value in the cell in column B.

If a cell in column B happens to be ABC, I need that value copied 24 columns to the right.

ThaSub CopyColumn()
Dim c As Range
' Get Number of Lines and star scaning Row by Row
nlines = ActiveSheet.Range("A5").End(xlDown).Row
n_of_desc = 0
For i = 5 To nlines
Range("B" & i).Select
ActiveCell.Offset(0, 24).Value = ("B" & i).value
Next i
End Sub

Thanks to anyone for any help here.


VBA DOES NOT LIKE: ("B" & i).value for whatever reason!?
 
Hi Peter

Good learning experience for me.

Just some points:

Macro does not pick up any data in row 1. (this is ok I can be happy with that.)

With the first entry for search - can I put in say: font.bold and it selects any row with bold text or any type of font selected ?


Regards

Charlie
 
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Macro does not pick up any data in row 1. (this is ok I can be happy with that.)
That's correct. The code uses AutoFilter to find the data and AutoFilter requires a heading row. You could either
a) permanently insert a heading row, or
b) the code could, each time it is run
- insert a heading row
- do the filter/copy
- remove the heading row


With the first entry for search - can I put in say: font.bold and it selects any row with bold text or any type of font selected ?
No, not with this sort of code. Trying to find and copy based on formatting would be considerably more difficult and would require a different code approach.
 
Upvote 0
Hi Peter

Thanks for the info. I keep the code as is. I dont normally use row 1 much at all. So problem resolved.


The font problem I wwill forget about.

Thanks

Charlie
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,233
Members
453,152
Latest member
ChrisMd

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