如何循环一行数据并插入公式 [英] How do I loop a row of data and insert formula

查看:93
本文介绍了如何循环一行数据并插入公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的宏如何工作,我输入一个用逗号分隔的集合整数(行号),我将这些数字拆分成单独的单元格。



然后,使用循环我将使用行号并相应地更新行。



将输入数据分成单独的数字并将它们插入第一行表格中的单独单元格中

 < span class =code-keyword> Sub  btnResetSelected()


Dim resetRow As String
Dim i As 整数
Dim As Variant

' 从逗号分隔的单元格中获取单独的行
resetRow = Range( C10)。值

Rows = Split(resetRow,

对于 i = 0 UBound(行)

单元格( 1 ,i + 1 )。值=行(i)

下一步 i


结束 Sub





我现在用于插入公式的内容:

  Dim  resetRow1 作为 整数 
Dim resetRow2 As 整数

resetRow1 =范围( A1)。值

范围(< span class =code-string> F& (resetRow1)& :我& (resetRow1))。公式= = G10_Anchor + short_end_increment *(base_year-F $ 57)

resetRow2 =范围( A2)。价值

范围( F&(resetRow2)& :我&(resetRow2))。公式= = G10_Anchor + short_end_increment *(base_year-F $ 57)





我不知道想要为每个单元格硬编码,以防用户在单元格中输入大量单独的整数,循环工作/帮助?

解决方案

57)

resetRow2 =范围( A2)。

范围( F& (resetRow2)& :我& (resetRow2))。公式= = G10_Anchor + short_end_increment *(base_year -F


< blockquote> 57)





我不想为每个单元格硬编码,以防万一用户输入很多单独的整数进入单元格,循环工作/帮助?


How my macro will work is, I input a set integers (row numbers) seperated by commas and I will split up these numbers into seperate cells.

Then, using a loop I will use the row numbers and update the rows accordingly.

Seperate input data into seperate numbers and insert them into seperate cells on first row of sheet

Sub btnResetSelected()


Dim resetRow As String
Dim i As Integer
Dim Rows As Variant

'To get seperate rows from cell seperated by comma
resetRow = Range("C10").Value

Rows = Split(resetRow, ",")

For i = 0 To UBound(Rows)

Cells(1, i + 1).Value = Rows(i)

Next i


End Sub



What I have now for the insertion of formula:

Dim resetRow1 As Integer
Dim resetRow2 As Integer

resetRow1 = Range("A1").Value

Range("F" & (resetRow1) & ":I" & (resetRow1)).Formula = "=G10_Anchor+short_end_increment*(base_year-F$57)"

resetRow2 = Range ("A2").Value

Range("F" & (resetRow2) & ":I" & (resetRow2)).Formula = "=G10_Anchor+short_end_increment*(base_year-F$57)"



I do not want to hard code this for every cell just in case the user inputs a lot of seperate integers into the cell, will a loop work/help?

解决方案

57)" resetRow2 = Range ("A2").Value Range("F" & (resetRow2) & ":I" & (resetRow2)).Formula = "=G10_Anchor+short_end_increment*(base_year-F


57)"



I do not want to hard code this for every cell just in case the user inputs a lot of seperate integers into the cell, will a loop work/help?


这篇关于如何循环一行数据并插入公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆