I am fairly new at VBA and have been working on this for the past couple of days. I am having trouble using the values submitted through a UserForm. I would like to use the values (rows, columns, x distance and y distance) in another module to set the number of loops needed to populate my data as well as the value needed to add to each data when populating them. The values that o store in nRow, nCol... could not be retrieved in the module.
UserForm code:
Module Code:
UserForm code:
Code:
Private Sub CheckBox1_Click() Dirt = 2
End Sub
Private Sub cmdbtn_cancel_Click()
Unload Me
End Sub
Private Sub cmdbtn_enter_Click()
nRow = DataInput.txtRow
nCol = DataInput.txtCol.Value
xCoord = DataInput.txtx.Value
yCoord = DataInput.txty.Value
DataInput.Hide
Unload DataInput
End Sub
Private Sub txtCol_Change()
End Sub
Private Sub UserForm_Initialize()
Dirt = 1
txtRow.SetFocus
End Sub
Module Code:
Code:
Public nRow As Integer
Public nCol As Integer
Public xCoord As Long
Public yCoord As Long
Public Dirt As Long
Public Sub TestDir()
DataInput.Show
Range("A13").Select
' start of data table
ActiveCell.Offset(1, 4).Select
' go to first value of x-ref
Range(ActiveCell, ActiveCell.End(xlToRight).End(xlDown)).Select
' select all values of x-ref and y-ref
For Each c In Selection
c.Activate
ActiveCell.FormulaR1C1 = "= " & ActiveCell.Formula
Next c
If Dirt = 1 Then
Do While cntCol <= nCol
If cntCol = nCol And cntRow = nRow Then
ActiveCell.CurrentRegion.Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "'" & Num
Else
Num = Num + 1
ActiveCell.CurrentRegion.Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select
ActiveCell.FormulaR1C1 = "'" & Num
End If
If cntRow <= nRow Then
cntRow = cntRow + 1
If cntRow = nRow + 1 And cntCol = 1 Then
If cntCol Mod 2 <> 0 Then
Paste_Sub_Y (yCoord)
Else
Paste_Add_Y (yCoord)
End If
ElseIf cntRow <= nRow Then
If cntCol Mod 2 <> 0 Then
Paste_Sub_Y (yCoord)
Else
Paste_Add_Y (yCoord)
End If
End If
'<------------Other codes------------->
End Sub