Increment excel formula by 1

前端 未结 4 945
醉话见心
醉话见心 2021-01-19 15:44

I\'m trying to copy and paste a few cells keeping the format and them ebing linked to a table.

Currently i have a table but i am referencing it from another sheet e.

4条回答
  •  误落风尘
    2021-01-19 16:23

    Here's some Code I've Written for myself. It's fairly simple to edit with changeable increments and Row spacings.

    Sub MakeFormulas()
        Dim sh As Worksheet: Set sh = ActiveWorkbook.Sheets("YourWorksheet")
        Dim field As String
        Dim formula As String
        Dim i As Integer: i = 2 'Every x Line you want to Paste your Formula to
        Dim a As Integer: a = 7 'Starting Row Number of Data on the Sheet you want to fetch
        Do While i < 1000 'How many Rows down you wan't to paste it to
            field = "C" + CStr(i) 'Column where you paste to + The Row Number
            formula = "=Switches!A" + CStr(a) 'The Reference Column + Row Number which gets incremented.
            sh.Range(field) = formula
    
            a = a + 1 'By which Number your FOrmula should get incremented
            i = i + 2 'Every i (Second) row gets the Formula Pasted.
        Loop
    End Sub
    

提交回复
热议问题