简体   繁体   中英

Excel VBA - add a value to a cell in a certain row

I'm very new to Excel VBA and I'm trying to getting figure out certain things. I want to populate cells in a range K26:K386 with a value that comes from cell N47 (call it "Income)". The cell to be populated (among those rows in K26:386 ) is determined by a number in cell N46 (call it "Month"). "Income" can be any figure. "Month" can be any figure from 1 to 360.

I want to plug in two inputs into cells N47 and N46 - income and the respective month - such that the respective cell in range K26:K386 is populated with the "Income" value for the respective month from 1 to 360. Can somebody please advise? I only know how to populate a single cell like this:

Sub Ievietot()
    Dim Sum As Integer
    Sum = Range("N47").Value
    Range("K30").Value = Sum
End Sub

I think that this can be done as follows:

Sub CopyData()
    Dim iMonthNum as Integer
    Dim income as Integer

    iMonthNum = Range("N46").Value
    income = Range("N47").Value
    Range("K" & (25 + iMonthNum)).Value = income
End Sub

你可以用

Range("K26:K386").Cells(Range("N46").Value) = Range("N47").Value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM