Copy specific cell value in array to another worksheet

03856me

Active Member
Joined
Apr 4, 2008
Messages
297
Goal: Loop through rows on a specific worksheet (Sheet1) and copy values in specific columns to another worksheet to specific sheets.
Progress: This code works perfectly when looping through all the worksheets.
Question: How do I loop through rows and not worksheets?

Help please, I am having no luck finding what I want, any help if appreciated so much.


VBA Code:
Sub CreateTest()
    
Dim wb As Workbook
    Set wb = ThisWorkbook
Dim ws As Worksheet
    Set ws = wb.Sheets("test")

    
For Each ws In Worksheets
    If ws.Name <> "Upload" And ws.Name <> "test" Then
    
    Range("D999").End(xlUp).Offset(1, 0).Value = ws.Range("B").Value             'New column location column B
    Range("E999").End(xlUp).Offset(1, 0).Value = ws.Range("F15").Value           'New column location column C
    Range("F999").End(xlUp).Offset(1, 0).Value = ws.Range("G44").Value           'New column location column E
    Range("L999").End(xlUp).Offset(1, 0).Value = ws.Range("I39").Value           'New column location column F
    Range("M999").End(xlUp).Offset(1, 0).Value = ws.Range("G39").Value           'New column location column J
    
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
For example:
VBA Code:
Dim myRange As Range, I As Long
'..
'..
Set myran = Sheets("One").Range("C10:H100")
'
For I = myRange.Cells(1, 1).Row To (myRange.Cells(1, 1).Row + myRange.Rows.Count)
    Destination1.Value = myRange.Cells(I, "B").Value     'column B
    Destination2.Value = myRange.Cells(I, "F").Value     'column F
' etc
' etc
Next I
 
Upvote 0
Thanks Anthony47. I am getting an error on Destination1.Value row
How do I define Destination1, and also, does this code cycle through all the rows?
 
Upvote 0
DESTINATION is a label, you should know how calculate where information have to be written...

To mimick one of your previous instruction:
VBA Code:
For I = myRange.Cells(1, 1).Row To (myRange.Cells(1, 1).Row + myRange.Rows.Count)
  
    Range("E999").End(xlUp).Offset(1, 0).Value = myRange.Cells(I, "F").Value   'column F

'etc
Next I
And Yes, For I /Next I will have the same instruction executed on all the rows of the range
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,715
Members
448,985
Latest member
chocbudda

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