Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

R1C1 Issue populating cells within Excel

Status
Not open for further replies.

collierd

MIS
Dec 19, 2001
509
DE
Hello

I have the following macro running within Excel:


Code:
 Dim rowReference As Integer
    Dim columnCounter As Integer
    Dim budgetCodeCounter As Integer
   
    rowReference = 2
    
    For budgetCodeCounter = 1 To 4
        For columnCounter = 1 To 12
            Cells(rowReference, 1) = "=budget!R1C2"
            Cells(rowReference, 2) = "=TEXT(budget!R4C" & columnCounter - 1 & "], ""dd/mm/yyyy"")"
            Cells(rowReference, 3) = "=budget!R[" & budgetCodeCounter + 4 & "]C1"
            Cells(rowReference, 4) = "=budget!R5C[" & columnCounter - 3 & "]"
 
            rowReference = rowReference + 1
        Next columnCounter
    Next budgetCodeCounter
I can't quite work out why data is being populated the way it is.
Cells(rowReference, 3) = "=budget!R[" & budgetCodeCounter + 4 & "]C1" populates using incremental rows (row 7 through to row 57)
This should have 12 instances of the first cell followed by 12 of the next etc

Cells(rowReference, 2) = "=TEXT(budget!R4C[" & columnCounter - 1 & "], ""dd/mm/yyyy"")" uses -1
yet Cells(rowReference, 4) = "=budget!R5C[" & columnCounter - 3 & "]" uses -3 to get the same columns on a different row

Is it using some sort of offset?
How does this work?

Thanks

Damian.
 
I can't quite work out why data is being populated the way it is.
Cells(rowReference, 3) = "=budget!R[" & budgetCodeCounter + 4 & "]C1" populates using incremental rows (row 7 through to row 57)
This should have 12 instances of the first cell followed by 12 of the next etc

Cells(rowReference, 2) = "=TEXT(budget!R4C[" & columnCounter - 1 & "], ""dd/mm/yyyy"")" uses -1
yet Cells(rowReference, 4) = "=budget!R5C[" & columnCounter - 3 & "]" uses -3 to get the same columns on a different row

Is it using some sort of offset?
How does this work?
You don't seem to have realised how relative referencing works in Excel. Square brackets in a R1C1 formula indicate relative offsets.

Does that explain it?

Cheers, Glenn.

Did you hear about the literalist show-jumper? He broke his nose jumping against the clock.
 
It does Glenn

I can't see what this is relative to
I will have a look into this

Should I be using the method
Could I perform this without relative referencing?
 



Hi,

A Range Object has many PROPERTIES. Two are the VALUE property and the FORMULA property. I think that the complier must be ASSUMING the VALUE property...
Code:
Cells(rowReference, 1)[b].formule[/b] = "=budget!R1C2"

Skip,
[sub]
[glasses] [red][/red]
[tongue][/sub]
 
Looking good now thanks
Using relative referencing method

Damian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top