how can use array with this long lines code?

leap out

Active Member
Joined
Dec 4, 2020
Messages
271
Office Version
  1. 2016
  2. 2010
hello
I have this code but it's very slow if anybody has make shorter by using array I truly appreciate
VBA Code:
Private Sub CommandButton1_Click()
 Dim ws As Worksheet, matchFormula1, matchFormula2, matchFormula13 As String, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9 As String
    Set ws = Sheets("Sheet1")
    cb1 = ComboBox1.Text
    cb2 = ComboBox2.Text
    cb3 = ComboBox3.Text
    cb4 = ComboBox4.Text
    cb5 = ComboBox5.Text
    cb6 = ComboBox6.Text
    cb7 = ComboBox7.Text
    cb8 = ComboBox8.Text
    cb9 = ComboBox9.Text
    
    matchFormula1 = "match(" & Chr(34) & cb1 & cb2 & cb3 & Chr(34) & ",A:A&B:B&C:C,0)"
    matchFormula2 = "match(" & Chr(34) & cb4 & cb5 & cb6 & Chr(34) & ",A:A&B:B&C:C,0)"
   matchFormula3 = "match(" & Chr(34) & cb7 & cb8 & cb9 & Chr(34) & ",A:A&B:B&C:C,0)"
    On Error Resume Next
    ws.Cells(Evaluate(matchFormula1), ws.Columns.Count).End(xlToLeft).Offset(, 1) = TextBox1.Value
    ws.Cells(Evaluate(matchFormula2), ws.Columns.Count).End(xlToLeft).Offset(, 1) = TextBox2.Value
    ws.Cells(Evaluate(matchFormula3), ws.Columns.Count).End(xlToLeft).Offset(, 1) = TextBox3.Value
    On Error GoTo 0
End Sub
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
this the whole code
VBA Code:
Private Sub CommandButton1_Click()
 Dim ws As Worksheet, matchFormula1, matchFormula2, matchFormula13 As String, cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9 As String
    Set ws = Sheets("Sheet1")
    cb1 = ComboBox1.Text
    cb2 = ComboBox2.Text
    cb3 = ComboBox3.Text
    cb4 = ComboBox4.Text
    cb5 = ComboBox5.Text
    cb6 = ComboBox6.Text
    cb7 = ComboBox7.Text
    cb8 = ComboBox8.Text
    cb9 = ComboBox9.Text
    
   matchFormula1 = "match(" & Chr(34) & cb1 & cb2 & cb3 & Chr(34) & ",A1:A" & lastrow & " & B1:B" & lastrow & " & C1:C" & lastrow & ",0)"
    matchFormula2 = "match(" & Chr(34) & cb4 & cb5 & cb6 & Chr(34) & ",A1:A" & lastrow & " & B1:B" & lastrow & " & C1:C" & lastrow & ",0)"
   matchFormula3 = "match(" & Chr(34) & cb7 & cb8 & cb9 & Chr(34) & ",A1:A" & lastrow & " & B1:B" & lastrow & " & C1:C" & lastrow & ",0)"
    On Error Resume Next
    ws.Cells(Evaluate(matchFormula1), ws.Columns.Count).End(xlToLeft).Offset(, 1) = TextBox1.Value
    ws.Cells(Evaluate(matchFormula2), ws.Columns.Count).End(xlToLeft).Offset(, 1) = TextBox2.Value
    ws.Cells(Evaluate(matchFormula3), ws.Columns.Count).End(xlToLeft).Offset(, 1) = TextBox3.Value
    On Error GoTo 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,973
Messages
6,122,534
Members
449,088
Latest member
RandomExceller01

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