简体   繁体   English

EXCEL中的VBA。 自动填充权限

[英]VBA in EXCEL. AUTOFILL RIGHT

How can I do an autofill to the right?如何在右侧进行自动填充?

I've searched and tried to replicate the same steps that I saw on other threads but it didn't worked for me.我已经搜索并尝试复制我在其他线程上看到的相同步骤,但它对我不起作用。 Maybe for some lack of intuition.也许是因为缺乏直觉。

My sheet is generating a new sheet from VBA (its a monte carlos simulation).我的工作表正在从 VBA 生成一个新工作表(它是蒙特卡洛斯模拟)。 I want to generate a new line on top of the matrix and fill the line from B1 to the last column with "0,1,2,...,X"我想在矩阵顶部生成一个新行,并用“0,1,2,...,X”填充从 B1 到最后一列的行

I've tried the following code:我试过以下代码:

Sheets("valores").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("B1").Select
ActiveCell.FormulaR1C1 = "0"
Range("B2").Select
Selection.End(xlToRight).Select
Range("LastColumn"&1).Select
Range(Selection, Selection.End(xlToLeft)).Select
Selection.DataSeries Rowcol:=xlRows, Type:=xlLinear, Date:=xlDay, Step _
    :=1, Trend:=False

  
  MsgBox "Sheet generated."
  

Can someone give me some help on this?有人可以给我一些帮助吗? Thank you!谢谢!

Supposing you want to fill to the right from cell B1 to cell X, incrementing the value 1 serially, then you could use the following code: Assuming cell X is for example Z1, you have:假设您想从单元格 B1 向右填充到单元格 X,连续递增值 1,那么您可以使用以下代码:假设单元格 X 是例如 Z1,您有:

Range("B1").Value=0
Range("B1").Select
Selection.Autofill Destination :=Range("B1:Z1"), Type 
:=xlFillSeries

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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