No repetir codigo en un select case
TENGO UN CODIGO CON SELECT CASE QUE SE APLICA PARA 45 HOJAS DE EXCEL, NECESITO QUE NO SE REPITA TANTAS VECES, ESTE ES UNA PARTE DEL CODIGO PARA LOS PRIMERAS 3 HOJAS, AL
SELECCIONAR UN COMBOBOX SE ENVIA SEGUN SEA EL CASO
Select Case ComboBoxJuz.Value
Case "JUAN HERNANDEZ"
Worksheets("Hoja1").Activate
Range("A1").Select
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = ComboBoxNo
Cells(NextRow, 2) = TxtCausa
Cells(NextRow, 3) = TextBox2
Cells(NextRow, 4) = ComboBoxJuz
Cells(NextRow, 5) = TxtBla2
Cells(NextRow, 6) = ComboBoxTipo
Cells(NextRow, 7) = UCase(TxtIncul)
Cells(NextRow, 8) = ComboBoxDeli
Cells(NextRow, 9) = ComboBoxResp
Cells(NextRow, 10) = ComboBoxTra
Cells(NextRow, 11) = ComboBoxGru
Cells(NextRow, 12) = ComboBoxTipo2
Cells(NextRow, 13) = CDate(TextBox3.Text)
Sheets("Hoja1").Activate
Columns("I:I").Select
ActiveWorkbook.Worksheets("Hoja1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja1").Sort.SortFields.Add Key:=Range("I1").End(xlDown), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BASEGENE").Sort
.SetRange Range("A1:M17")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Case "PEDRO PEREZ"
Worksheets("Hoja2").Activate
Range("A1").Select
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = ComboBoxNo
Cells(NextRow, 2) = TxtCausa
Cells(NextRow, 3) = TextBox2
Cells(NextRow, 4) = ComboBoxJuz
Cells(NextRow, 5) = TxtBla2
Cells(NextRow, 6) = ComboBoxTipo
Cells(NextRow, 7) = UCase(TxtIncul)
Cells(NextRow, 8) = ComboBoxDeli
Cells(NextRow, 9) = ComboBoxResp
Cells(NextRow, 10) = ComboBoxTra
Cells(NextRow, 11) = ComboBoxGru
Cells(NextRow, 12) = ComboBoxTipo2
Cells(NextRow, 13) = CDate(TextBox3.Text)
Sheets("Hoja2").Activate
Columns("I:I").Select
ActiveWorkbook.Worksheets("Hoja2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja2").Sort.SortFields.Add Key:=Range("I1").End(xlDown), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BASEGENE").Sort
.SetRange Range("A1:M17")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Case "JOSE RAMIREZ"
Worksheets("hoja3").Activate
Range("A1").Select
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = ComboBoxNo
Cells(NextRow, 2) = TxtCausa
Cells(NextRow, 3) = TextBox2
Cells(NextRow, 4) = ComboBoxJuz
Cells(NextRow, 5) = TxtBla2
Cells(NextRow, 6) = ComboBoxTipo
Cells(NextRow, 7) = UCase(TxtIncul)
Cells(NextRow, 8) = ComboBoxDeli
Cells(NextRow, 9) = ComboBoxResp
Cells(NextRow, 10) = ComboBoxTra
Cells(NextRow, 11) = ComboBoxGru
Cells(NextRow, 12) = ComboBoxTipo2
Cells(NextRow, 13) = CDate(TextBox3.Text)
Sheets("Hoja3").Activate
Columns("I:I").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Add Key:=Range("I1").End(xlDown), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BASEGENE").Sort
.SetRange Range("A1:M5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
SELECCIONAR UN COMBOBOX SE ENVIA SEGUN SEA EL CASO
Select Case ComboBoxJuz.Value
Case "JUAN HERNANDEZ"
Worksheets("Hoja1").Activate
Range("A1").Select
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = ComboBoxNo
Cells(NextRow, 2) = TxtCausa
Cells(NextRow, 3) = TextBox2
Cells(NextRow, 4) = ComboBoxJuz
Cells(NextRow, 5) = TxtBla2
Cells(NextRow, 6) = ComboBoxTipo
Cells(NextRow, 7) = UCase(TxtIncul)
Cells(NextRow, 8) = ComboBoxDeli
Cells(NextRow, 9) = ComboBoxResp
Cells(NextRow, 10) = ComboBoxTra
Cells(NextRow, 11) = ComboBoxGru
Cells(NextRow, 12) = ComboBoxTipo2
Cells(NextRow, 13) = CDate(TextBox3.Text)
Sheets("Hoja1").Activate
Columns("I:I").Select
ActiveWorkbook.Worksheets("Hoja1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja1").Sort.SortFields.Add Key:=Range("I1").End(xlDown), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BASEGENE").Sort
.SetRange Range("A1:M17")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Case "PEDRO PEREZ"
Worksheets("Hoja2").Activate
Range("A1").Select
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = ComboBoxNo
Cells(NextRow, 2) = TxtCausa
Cells(NextRow, 3) = TextBox2
Cells(NextRow, 4) = ComboBoxJuz
Cells(NextRow, 5) = TxtBla2
Cells(NextRow, 6) = ComboBoxTipo
Cells(NextRow, 7) = UCase(TxtIncul)
Cells(NextRow, 8) = ComboBoxDeli
Cells(NextRow, 9) = ComboBoxResp
Cells(NextRow, 10) = ComboBoxTra
Cells(NextRow, 11) = ComboBoxGru
Cells(NextRow, 12) = ComboBoxTipo2
Cells(NextRow, 13) = CDate(TextBox3.Text)
Sheets("Hoja2").Activate
Columns("I:I").Select
ActiveWorkbook.Worksheets("Hoja2").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja2").Sort.SortFields.Add Key:=Range("I1").End(xlDown), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BASEGENE").Sort
.SetRange Range("A1:M17")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
Case "JOSE RAMIREZ"
Worksheets("hoja3").Activate
Range("A1").Select
NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
Cells(NextRow, 1) = ComboBoxNo
Cells(NextRow, 2) = TxtCausa
Cells(NextRow, 3) = TextBox2
Cells(NextRow, 4) = ComboBoxJuz
Cells(NextRow, 5) = TxtBla2
Cells(NextRow, 6) = ComboBoxTipo
Cells(NextRow, 7) = UCase(TxtIncul)
Cells(NextRow, 8) = ComboBoxDeli
Cells(NextRow, 9) = ComboBoxResp
Cells(NextRow, 10) = ComboBoxTra
Cells(NextRow, 11) = ComboBoxGru
Cells(NextRow, 12) = ComboBoxTipo2
Cells(NextRow, 13) = CDate(TextBox3.Text)
Sheets("Hoja3").Activate
Columns("I:I").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Hoja3").Sort.SortFields.Add Key:=Range("I1").End(xlDown), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("BASEGENE").Sort
.SetRange Range("A1:M5")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("A1").Select
1 respuesta
Respuesta
1