简体   繁体   English

我该怎么设置“Dim y As”?

[英]What do I set “Dim y As”?

So what I'm trying to do is order my list 1 through whatever the bottom # is. 所以我要做的就是通过底部#是命令我的列表1。 Within doing so I'm in a way moving all of my information to the right. 在这样做的过程中,我将把所有信息都移到右边。 Then I'm going to the bottom of my selection to find the bottom of my list in column B. and then left 1, to find what the bottom A column to fill in a # system all the way down to the bottom of the list. 然后我将在我的选择的底部找到列B中列表的底部然后离开1,找到底部A列填充#系统一直到列表的底部。

Private Sub CommandButton2_Click()
       'My problem is i don't know what to set "Dim y As Range" I know Range is 
       'incorrect along with Long, and Integer.
    Dim y As Range
    Sheets("PalmFamily").Select
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "1"
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "2"
    Range("A3").Select
    ActiveCell.FormulaR1C1 = "3"
    Range("A1:A3").Select
       'As you can notice I also have a weird code 
       '" y = Range("B1").End(xlDown).Offset(0, -1)" I'm trying to go to the bottom 
       'of my list then move left 1. 
    y = Range("B1").End(xlDown).Offset(0, -1)
       'As well the I'm not sure if I set my range to be correct when I do
       '"Range("A1,y")"
    Selection.AutoFill Destination:=Range("A1,y"), Type:=xlFillDefault
    Range("A1,y").Select
End Sub

The code you posted does not compile, I can tell that just by looking at it. 您发布的代码无法编译,我只能通过查看它来判断。

You have declared y As Range which is an object, which requires the Set keyword when assigning. 您已声明y As Range是一个对象,在分配时需要Set关键字。

Set y = Range("B1").End(xlDown).Offset(0, -1)

Furthermore, Range("A1,y") is a syntax error that I see in two places. 此外, Range("A1,y")是我在两个地方看到的语法错误。 Both of these, I think, should be changed to : 我认为,这两个都应改为:

Range("A1", y)

Note that the comma and the "y" are not enclosed in the quote marks. 请注意,逗号和“y”未包含在引号中。

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

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