how implement code on userform for multiple ranges names instead of sheets

Ali M

Active Member
Joined
Oct 10, 2021
Messages
290
Office Version
  1. 2019
  2. 2013
Platform
  1. Windows
Hi guys
first I have combobox contains sheets names , but should show ranges names and I have textbox1,2,3
so when I select the range name wherever(somtimes two ranges names in the same sheet or each range is in every sheet )
for instance range name(DATA) should copy from textboxes to columns A2:D for range name(DATA) , and range name(source) should copy from textboxes to columns H2:K range name(source) .both ranges name are existed in TRANSACTION sheet name
another range name(EXPORT) should copy from textboxes to columns C2:F for range name(EXPORT) in OUTPUT sheet name .
so what I need :
1- populate all of the ranges names are existed in specific sheets(TRANSACTION, OUTPUT) if it's possible without using helper column for ranges names.
2-when select specific range name from combobox1 implement the code for selected range name
VBA Code:
Private Sub CommandButton1_Click()
Dim lr As Long, sh As Worksheet
'Dim Cl As Range


If ComboBox1.Value = "" Then Exit Sub

Set sh = Sheets(ComboBox1.Value)

With sh
  
    .Activate
    lr = .Range("A" & .Rows.Count).End(xlUp).Row
   
    .Range("B" & lr + 1) = TextBox1.Value
    .Range("C" & lr + 1) = TextBox2.Value
    .Range("D" & lr + 1) = TextBox3.Value
    .Range("E" & lr + 1) = TextBox4.Value
    .Range("A" & lr + 1) = lr
    .Columns(1).NumberFormat = "General"
End With
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

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