开发者

Value from TextBox\Combobox to Range

开发者 https://www.devze.com 2023-04-07 03:49 出处:网络
UserForm1.TextBox1.Value = \"G4\"开发者_运维问答 Set CodeRange = Range(UserForm1.TextBox1.Value, Cells(Rows.Count, \"G\").End(xlUp))
UserForm1.TextBox1.Value = "G4"开发者_运维问答

Set CodeRange = Range(UserForm1.TextBox1.Value, Cells(Rows.Count, "G").End(xlUp))

Gives: methog range of object _global failed

Pls some help how to convert value from form to range.


Your code looks okay to me, although slightly unorthodox. Have you dimensioned CodeRange as a range?

If the activehseet is a chart sheet you will get that error.

You should also fully qualify your reference with the worksheet or activesheet.

With WorkSheeets("Sheet1")
    Set CodeRange = .Range(UserForm1.TextBox1.Value, .Cells(Rows.Count, "G").End(xlUp))
End With

If your code is residing in the Userform module then you can use the Me keyword instead of Userfrom1.

I prefer to get ranges from the user using a input box like this:

Sub HTH()

    Dim rRange As Range

    On Error Resume Next
    rRange = Application.InputBox(Prompt:= _
            "Please select a range with your Mouse to be bolded.", _
            Title:="SPECIFY RANGE", Type:=8)
    On Error GoTo 0

    If Not rRange Is Nothing Then
        '// Your code here
    End If


End Sub


Decimal sphvalue = Decimal.Parse(cmbo_sph.SelectedValue.ToString());

        txt_sph.Text = sphvalue.ToString();
        Decimal cylvalue = Decimal.Parse(cmbo_cyl.SelectedValue.ToString());
        txt_cyl.Text = cylvalue.ToString();
        try
        {
        SqlConnection searchconnnection = new SqlConnection("DataSource=ANI\\SQLEXPRESS;Initial Catalog=divinei;Integrated Security=True");
            searchconnnection.Open();
            SqlCommand searchcommand = new SqlCommand("SELECT CL_sphValue,CL_CylValue FROM ConvertCharts where SP_sphValue=" + Decimal.Parse(txt_sph.Text) + " and Sp_CylValue=" + Decimal.Parse(txt_cyl.Text) + " ", searchconnnection);
            searchcommand.ExecuteNonQuery();
            SqlDataReader convertreader = searchcommand.ExecuteReader();
            while (convertreader.Read())
            {
                sphtxt.Text = convertreader[0].ToString();
                cyltxt.Text = convertreader[1].ToString();
            }
        }
        catch (Exception ex)
        {
            ex.ToString();
        }`enter code here`
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号