PDA

View Full Version : Solved: update from one excel to other file



white_flag
01-15-2012, 05:46 AM
hello
I have an excel file that will update via an user form, some fileds in the same excel file. this is the code


Private Sub CommandButton114_Click()
Dim LastRow As Long
Dim ws As Worksheet
Set ws = Worksheets("company")

With ws
LastRow = .Sheets(1).Cells.Find(What:="*", After:=[a1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets(2).Range("A2", Cells(LastRow, "A").Address).Value = ComboBox13.Value
.Sheets(2).Range("B2", Cells(LastRow, "B").Address).Value = TextBox11.Text
.Sheets(2).Range("C2", Cells(LastRow, "C").Address).Value = TextBox12.Text
End With

End Sub


how can be done this in a diffrent excel file (ex. companys.xls) not in this? Thank you

ps.sorry I put this in word forum. can be moved in excel forum.thx

white_flag
01-15-2012, 03:53 PM
Private Sub CommandButton114_Click()
Dim wb As Workbook
Dim ws As Worksheet
Dim LastRow As Long
Set ws = ActiveSheet
Set wb = Workbooks.Open(ThisWorkbook.Path & "\Companys.xls")
With wb
LastRow = .Sheets(1).Cells.Find(What:="*", After:=[a1], SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
.Sheets(2).Cells(LastRow, 1).Value = ComboBox13.Value
.Sheets(2).Cells(LastRow, 2).Value = TextBox11.Text
.Sheets(2).Cells(LastRow, 3).Value = TextBox12.Text
End With
wb.Save
wb.Close

End Sub

macropod
01-15-2012, 06:03 PM
Hi white_flag,

For your 'LastRow' variable, try:
LastRow = .Sheets(1).Cells.SpecialCells(xlCellTypeLastCell).Row