Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50139

Cant send Data to different workbook.

$
0
0
Im sending data to to a different Workbook. the workBook will be a basic electronic LogBook of transactions. I have it working with one minor issue. The first column is shifted down one row. "A1" is giving me all my problems. Please help me with this minor problem. I have been going at this for hours!! someone... BE MY HERO!!!

Code:

Sub Transfer_Data()Dim ThisWB As Variant
Dim LogBookName As Variant
Dim Lastrow As Long


ThisWB = ThisWorkbook.Name


Set LogBook = Workbooks.Open(fn)


LogBookName = LogBook.Name


   
With Workbooks(LogBookName).Sheets("sheet1")


'Find the last row used
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row


MsgBox Lastrow
'IGOR: heading and data will be on the same row.... need to seperat the rows


'Populat Heading
If checkHeading = True Then
   
    'Date Recorded 'Heading
If check1 = True Then
    If .Range("a" & Lastrow).Offset(1, 0).Value = "" Then
        .Range("a" & Lastrow).Offset(1, 0).Value = "Date Recorded:"
    Else
        .Range("Z" & Lastrow).End(xlToLeft).Offset(0, 1).Value = "Date Recorded:"
    End If
End If 'Date Recorded


'Type of Transaction 'Heading
If check2 = True Then
    If .Range("a" & Lastrow).Offset(1, 0).Value = "" Then
        .Range("a" & Lastrow).Offset(1, 0).Value = "Type of Transaction:"
    Else
        .Range("Z" & Lastrow).End(xlToLeft).Offset(0, 1).Value = "Type of Transaction:"
    End If
End If 'Type of Transaction


'Date of Transaction 'Heading
If check3 = True Then
    If .Range("a" & Lastrow).Offset(1, 0).Value = "" Then
        .Range("a" & Lastrow).Offset(1, 0).Value = "Date of Transaction:"
    Else
        .Range("Z" & Lastrow).End(xlToLeft).Offset(0, 1).Value = "Date of Transaction:"
    End If
End If 'Date of Transaction




End If '''''''''Heading






'Find the last row used again
Lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
MsgBox Lastrow


'Date Recorded
If check1 = True Then
    If .Range("a" & Lastrow).Offset(1, 0).Value = "" Then
        .Range("a" & Lastrow).Offset(1, 0).Value = Date
    Else
        .Range("Z" & Lastrow).End(xlToLeft).Offset(0, 1).Value = Date
    End If
End If 'Date Recorded


'Type of Transaction
If check2 = True Then
    If .Range("a" & Lastrow).Offset(1, 0).Value = "" Then
        .Range("a" & Lastrow).Offset(1, 0).Value = Sheet2.Range("AB7").Value & "/" & Sheet2.Range("B6").Value
    Else
        .Range("Z" & Lastrow).End(xlToLeft).Offset(0, 1).Value = Sheet2.Range("AB7").Value & "/" & Sheet2.Range("B6").Value
    End If
End If 'Type of Transaction


'Date of Transaction
If check3 = True Then
    If .Range("a" & Lastrow).Offset(1, 0).Value = "" Then
        .Range("a" & Lastrow).Offset(1, 0).Value = Sheet2.TextBox13.Text
    Else
        .Range("Z" & Lastrow).End(xlToLeft).Offset(0, 1).Value = Sheet2.TextBox13.Text
    End If
End If 'Date of Transaction








'''''''AUTO fIT Colomns
.Range("A1:Z2").Columns.Select 'autofit requires columns to be selected
.Range("A1:Z2").Columns.AutoFit




End With
   
'Lastly save and close Logbook
LogBook.Save
LogBook.Close






End Sub

See image to see what it spits out.
Untitled.gif

Viewing all articles
Browse latest Browse all 50139

Trending Articles