Hello,
I'm trying to select a specific sheet to paste my information to based of the information in 2 cells.
if cell 1 is A and cell 2 is A the information should be pasted in sheet 1 of workbook 2
if cell 1 is a and cell 2 is B the information should be pasted in sheet 2 of workbook 2
it will become a bigger datasheet but for now i would like to get this working.
so far I've tried the following:
Sub Button1_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ActiveWorkbook
Workbooks.Open ThisWorkbook.Path & "\" & "book2.xlsx"
Set wb2 = ActiveWorkbook
wb1.Activate
If Range("A1") = "A" And Range("B1") = "A" Then
wb2.Activate
Sheet1.Activate
Range("A4").Select
ActiveCell.Value = "sheet1"
ElseIf Range("A1") = "A" And Range("B1") = "B" Then
wb2.Activate
Sheet2.Activate
Range("A4").Select
ActiveCell.Value = "sheet2"
End If
End Sub
but this isn't working and I don't know why it doesn't...
am I using the And function wrong?
I'm trying to select a specific sheet to paste my information to based of the information in 2 cells.
if cell 1 is A and cell 2 is A the information should be pasted in sheet 1 of workbook 2
if cell 1 is a and cell 2 is B the information should be pasted in sheet 2 of workbook 2
it will become a bigger datasheet but for now i would like to get this working.
so far I've tried the following:
Sub Button1_Click()
Dim wb1 As Workbook
Dim wb2 As Workbook
Set wb1 = ActiveWorkbook
Workbooks.Open ThisWorkbook.Path & "\" & "book2.xlsx"
Set wb2 = ActiveWorkbook
wb1.Activate
If Range("A1") = "A" And Range("B1") = "A" Then
wb2.Activate
Sheet1.Activate
Range("A4").Select
ActiveCell.Value = "sheet1"
ElseIf Range("A1") = "A" And Range("B1") = "B" Then
wb2.Activate
Sheet2.Activate
Range("A4").Select
ActiveCell.Value = "sheet2"
End If
End Sub
but this isn't working and I don't know why it doesn't...
am I using the And function wrong?