Hi guys, I am trying to find a specific woksheet to open it and paste data.
I want to find the worksheet that is = to the combobox value so I can paste the data there, I was trying trought loop and if the loop matches the combobox then the sheet should open and following that I could start coding so data pastes there to.
Sorry for my bad English
VBA Code:
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Despesas")
Dim last_row As Long
last_row = Sheets("Despesas").Range("C" & Rows.Count).End(xlUp).Row
'Validation-----------------------------------------------------
If Me.ComboBox1.Value = "" Then
MsgBox "seleciona o Mes", vbCritical
Exit Sub
End If
If Me.ComboBox2.Value = "" Then
MsgBox "seleciona a Designação", vbCritical
Exit Sub
End If
If Me.TextBox1.Value = "" Then
MsgBox "Preenche a Data", vbCritical
Exit Sub
End If
If Me.TextBox5.Value = "" Then
MsgBox "Preenche o Valor", vbCritical
Exit Sub
End If
If Me.TextBox3.Value = "" Then
MsgBox "Preenche com o numero do Documento", vbCritical
Exit Sub
End If
If Me.TextBox4.Value = "" Then
MsgBox "Preenche com a Especificação", vbCritical
Exit Sub
End If
If Me.ComboBox3.Value = "" Then
MsgBox "Preenche com a Obra", vbCritical
Exit Sub
End If
'---------------------------------------------------------------
sh.Range("C" & last_row + 1).Value = Me.ComboBox1.Value
sh.Range("D" & last_row + 1).Value = Me.TextBox1.Value
sh.Range("E" & last_row + 1).Value = Me.TextBox5.Value
sh.Range("F" & last_row + 1).Value = Me.TextBox3.Value
sh.Range("G" & last_row + 1).Value = Me.ComboBox2.Value
sh.Range("H" & last_row + 1).Value = Me.TextBox4.Value
sh.Range("I" & last_row + 1).Value = Me.ComboBox3.Value
'---------------------------------------------------------------
[COLOR=rgb(235, 107, 86)]Workbooks.Open Filename:="C:\Users\Daniel\Desktop\Gestão\Gestão ScorpionPrestige\Obras"
For Each Worksheet In ActiveWorkbook.Worksheets
If Worksheets.Name = ComboBox3.Value Then
Worksheet.Open
Else
Next Worksheet
End If[/COLOR]
'---------------------------------------------------------------
Me.ComboBox1 = ""
Me.TextBox1 = ""
Me.TextBox5 = ""
Me.TextBox3 = ""
Me.ComboBox2 = ""
Me.TextBox4 = ""
Me.ComboBox3 = ""
'----------
End Sub
I want to find the worksheet that is = to the combobox value so I can paste the data there, I was trying trought loop and if the loop matches the combobox then the sheet should open and following that I could start coding so data pastes there to.
Sorry for my bad English