Copy a cell value and paste it down a column on the same sheet and all sheets in the workbook

Svandra

New Member
Joined
Feb 6, 2023
Messages
20
Office Version
  1. 2013
Platform
  1. Windows
Hi,

so, I'm a total Newbie to VBA and been working with it for 4 days now. So far, I could solve most of my question thanks to Google and trial and error but I'm stuck on the following:
I have a workbook full of sheets (20+). All workbooks look the same. In order to get the data Python readable I need to adjust columns. So, I have one cell in column C that holds a value. I need this value to be "transferred" to another column B and have it for all cells from B2:B. The code I wrote does nothing:
VBA Code:
Sub copy_paste_to_all_sheets()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Range("C1").Copy
ws.Range("D:D").PasteSpecial
Next ws
End Sub

What Am I doing wrong? Any help is appreciated!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try this
VBA Code:
Sub copy_paste_to_all_sheets()
Dim ws As Worksheet
        For Each ws In ThisWorkbook.Worksheets
        ws.Range("B:B").Value = ws.Range("C1").Value
        Next ws
End Sub
 
Upvote 0
Do you really want to copy the value of C1 into all 1,048,576 cells of column B, or only some of them?
 
Upvote 0
Do you really want to copy the value of C1 into all 1,048,576 cells of column B, or only some of them?
Took me a second to understand what you're talking about :-) You're right, I just want the data corresponding to all the entries of column I (I put the wrong column in the code - unfortunately, it's still not doing anything).
 
Upvote 0
Is the code located in the same workbook as the one where you want to copy the values?
 
Upvote 0
In that case your code should work, albeit with the wrong column. In what way isn't it working?
 
Upvote 0
it's doing nothing. just nothing
now it's giving me this error message:
1675782000325.png
 
Upvote 0
Are you sure the code is in the workbook you want to change, that looks as though it's in your personal.xlsb workbook.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,219
Members
452,619
Latest member
Shiv1198

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