Using ComboBox and TextBox in a UserForm as the Range VBA

Tdorman

New Member
Joined
Aug 12, 2021
Messages
40
Office Version
  1. 2016
Platform
  1. Windows
I am trying to have the ComboBox1 selection determine the row that the value from TextBox3 will be placed, as well as have TextBox2 determine the column that it will go in. The below code achieves the row that it will be placed, however, I can't seem to get the column to work correctly.

This version of the code is placing the value in the column number of TextBox2. So if I input 10 as the ID, then the textbox3 value will be placed in the tenth column. I need the textbox2 value to act as a lookup on row 4, while maintaining the ability to determine the row based on the ComboBox1

VBA Code:
Private Sub CommandButton1_Click()

Dim ws As Worksheet
Dim N As Long
Dim i As Long
Dim Rng As Range

Set ws = Sheets("C-Proposal-19")
Set Rng = ws.Range("4:4").Find(Me.TextBox2.Value)

N = Worksheets("C-Proposal-19").Cells(Rows.Count, "B").End(xlUp).Row

For i = 5 To N
    If Worksheets("C-Proposal-19").Cells(i, "B").Value = frmAddAdj.ComboBox1.Value Then
        Worksheets("C-Proposal-19").Cells(i, "Rng").Value = frmAddAdj.TextBox3.Text
        Exit Sub
    End If
Next i


End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
try
VBA Code:
        Worksheets("C-Proposal-19").Cells(i, Rng.Column).Value = frmAddAdj.TextBox3.Text
 
Upvote 0
Solution

Forum statistics

Threads
1,214,805
Messages
6,121,665
Members
449,045
Latest member
Marcus05

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top