VBA worksheet and cell refference question

KevH

Board Regular
Joined
Apr 24, 2007
Messages
104
Howdy all,

I'm trying to build my "ChildSheet" dynamically based on data from the "ParentSheet". Data from columns in the ParentSheet will be copied to areas of the ChildSheet with headers and such added in between on the fly.

Here's an example of the copy portion. Please note the two different reffernece styles.

Code:
With ChildSheet

For i = 2 To LastRow
    .Cells(i + 2, 2) = "='" & ParentSheet & "'!D" & i
Next i

End with

' i=2 to skips the header on ParentSheet plus one row on ChildSheet
' Cells(i+2,2) skips two additional rows on ChildSheet

The effect of skipping the ParentSheet header and the three ChildSheet rows is what I want - the kludgy implmentation isn't.

1) How do I clean up the refferences to use just Cells()?
2) Are there proper names for the two types of refferences?
3) How do I clean up the for loop to be less lame?
4) Have I been slightly more clear than mud? :)


Thanks!
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi
try

Code:
Cells(i + 2, 2) = worksheets("ParentSheet").cells(i,4)
Or
Code:
a= "D2:D" & lastrow
b= worksheets("parentsheet").range(a).copy
worksheets("childsheet").cells(2,2).pastespecial
ravi
 
Upvote 0
The first code block made me go "Duh" and the second code block made me go "Ooooo".

Thanks!
 
Upvote 0

Forum statistics

Threads
1,222,398
Messages
6,165,771
Members
451,986
Latest member
samwize

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