我学习Visual Basic的工作,我现在在做编程新手(无经验)。 我一直在读了一天左右,终于决定开始制作所需的程序!
但是,我遇到了一些问题。
现在我有两个子程序。 第一个子程序让用户输入多少个数据对他们有这样我可以创建一个表让他们填,这是所以他们的数据在正确的地方为我以后引用它。
有那么他们按他们完成输入数据开始不同的子程序,将做一些计算,他们进入后的数字按钮。 我的问题是,我需要的,说他们有多少数据对结转到第二个程序中的变量。
我继续之前,这里是我到目前为止的代码! (你必须在窗口中向下滚动),我也应该注意到,第二子程序是在一个单独的模块。
Option Explicit
Public Counter As Long
Sub TableCreation1()
ActiveSheet.Shapes.Range(Array("Button 5")).Select
Selection.Delete
Counter = InputBox("How many pairs of data do you have? ")
Range("A1") = "Time (days)"
Range("B1") = "CFL (measured)"
Range("A1:B1").Font.Bold = True
Columns("A:B").EntireColumn.EntireColumn.AutoFit
Range("A1").Select
ActiveCell.Range("A1:B" & Counter + 1).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
End With
Dim btn As Button
Dim rng As Range
With Worksheets("Sheet1")
Set rng = .Range("A" & Counter + 2)
Set btn = .Buttons.Add(rng.Left, rng.Top, rng.Width, rng.Height)
With btn
.Caption = "Click this button to begin calculations"
.AutoSize = True
End With
End With
End Sub
Option Explicit
Dim IntermediateVariable As Long
Public Counter As Long
Sub FindCFLGuess()
IntermediateVariable = Worksheets("Sheet1").Range("B:B").Cells.SpecialCells(xlCellTypeConstants).Count
Counter = IntermediateVariable - 1
End Sub
为什么不是反携带到第二子程序的价值? 现在我有一个统计细胞在B列填写的金额,这给了我数的解决方法。 然而,这使得它让我不能就能够使用任何空间在B列的表的其余部分,我想用。
任何人都可以帮忙吗? 我认为,“公共”将使一个工作簿级的变量? 每当我做第二次显示计数器的值,它出现零。
很抱歉,如果我的代码是凌乱/低效。 我还在学习。 :)