Option Explicit
Private Sub UserForm_Initialize()
RefEditCell = ActiveSheet.Name & "!$A$1"
RefEditCol = ActiveSheet.Name & "!$A:$A"
End Sub
Private Sub cmdCreate_Click()
CreateFormula
ActiveWorkbook.Names.Add Name:=txtRangeName, RefersTo:=lblRangeFormula.Caption
End Sub
Private Sub cmdDelete_Click()
On Error GoTo Exits
Range(txtRangeName)(1).Select
DelName txtRangeName
Exits:
End Sub
Private Sub cmdRangeSelect_Click()
Range(txtRangeName).Select
End Sub
Private Sub CreateFormula()
Dim txt1 As String
Dim txt2 As String
Dim txt3 As String
Dim txt4 As String
txt1 = "=OFFSET(" & RefEditCell & "," & txtRowOffset & "," & txtColOffset & ","
txt2 = "COUNTA(" & RefEditCol & ")"
Select Case txtAdjust
Case Is < 0
txt3 = txtAdjust & ","
Case 0
txt3 = ","
Case Is > 0
If Left(txtAdjust, 1) = "+" Then
txt3 = txtAdjust & ","
Else
txt3 = "+" & txtAdjust & ","
End If
End Select
txt4 = txtCols & ")"
lblRangeFormula.Caption = txt1 & txt2 & txt3 & txt4
End Sub
Private Sub RefEditCell_Change()
Dim Sht As String
Dim Col As Long
Sht = Split(RefEditCell, "!")(0)
Col = Range(RefEditCell).Column
RefEditCol = Sht & "!" & Sheets(Sht).Columns(Col).AddressLocal
CreateFormula
End Sub
|