VBA code to copy cell value

sunilobo

New Member
Joined
Mar 29, 2021
Messages
10
Office Version
  1. 2010
Platform
  1. Windows
I need help in VBA code to copy cell value from rows of the sheet1 to other worksheets in the same workbook

Sheet1 - A5 to sheet2-F10
Sheet1 - A6 to sheet3-F10
Sheet1 - A7 to sheet4-F10

Thanks in advance
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this with a copy of your workbook.

VBA Code:
Sub Copy_Values()
  Dim i As Long
  
  With Sheets("Sheet1")
    For i = 1 To 3
      Sheets("Sheet" & i + 1).Range("F10").Value = .Range("A" & i + 4).Value
    Next i
  End With
End Sub
 
Upvote 0
Sub Copy_Values() Dim i As Long With Sheets("Sheet1") For i = 1 To 3 Sheets("Sheet" & i + 1).Range("F10").Value = .Range("A" & i + 4).Value Next i End With End Sub
Sorry didn't work maybe I was not clear. I have attached the sample file. I need to copy data from the main sheet from a row to the worksheets. Thanks so much for your quick response.
 

Attachments

  • Copydata.JPG
    Copydata.JPG
    34.7 KB · Views: 4
Upvote 0
That image does not clarify anything for me I'm afraid.

It has a column headed Values in main file "N8" but that column contains different values. How can N8 in the main file contain different values?

What does "main file" mean?
 
Upvote 0
That image does not clarify anything for me I'm afraid.

It has a column headed Values in main file "N8" but that column contains different values. How can N8 in the main file contain different values?

What does "main file" mean?
I have attached the file with the cell references. Hope now it will be clear. Sorry for inconvienance.

Also, do you have any VBA code to convert worksheets into pdf and save them on my computer. Thanks so much.
 

Attachments

  • Copydata.JPG
    Copydata.JPG
    42.6 KB · Views: 3
Upvote 0
What about this question?
What does "main file" mean?


Also, does the code need to read the worksheet names from the table you have shown or can it just hard-code "B1-001", "B1-002" etc?
If it has to read it from the table shown then I would need to know (at least) the worksheet name that table is on and what the columns and rows shown are.
 
Upvote 0
Hi
As per your layout
expected as
range.xlsm
ABCDMN
1
2
3
4
5N83377B1-001F10
6N93377B1-002F10
7N103532B1-101F10
8N113532B1-102F103377
9N123532B1-201F103377
10N133532B1-202F103532
113532
123532
133532
14
Sheet1


Try
VBA Code:
Sub test2()
    a = Sheets("sheet1").Cells(5, 1).CurrentRegion '<< sheet1 = main sheet
    For i = 1 To UBound(a)
        With Sheets(a(i, 3)).Range(a(i, 4))
          .Value = Sheets("sheet1").Range(a(i, 1))
        End With
    Next
End Sub
 
Upvote 0
VBA code is not working. Sheet names are not mentioned in the VBA code where the value has to be copied from the main sheet. Thanks
 
Upvote 0
But they are in column C are they?
Those are sheet names in column "C" wherein the values from "N8" has to go "F10" in Sheet name (B1-001). Please see attached sheet names.
 

Attachments

  • sheet names.JPG
    sheet names.JPG
    30 KB · Views: 3
Upvote 0

Forum statistics

Threads
1,215,208
Messages
6,123,642
Members
449,111
Latest member
ghennedy

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