Hello . I have a problem, where my VBA writes the same data in ALL the rows in the columns above instead of JUST the first empty one found. (To explain nearer: If I run the VBA-code the next day, then it writes the new data in the next empty row, BUT also overwrites the data from yesterday)
PLEASE help me fix this, so it only writes in the next empty row and does not overwrites the data above.
My VBA-code is as following:
Sub Dagsopdatering()
Sheets("Dagens pris").Select
Range("A1:G1000").Clear
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.ok.dk/priser/benzin-olie-priser", Destination:=Range("$A$1"))
.Name = "benzin-olie-priser"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Dim Emptyrow As Long
'Writes the date today'
Sheets("Priser").Select
Range("E4").Value = Date
Sheets("Info").Select
Range("G1").Value = Date
'Finds the first empty row in the column, and then copys into the first empty row'
Sheets("Priser").Select
Emptyrow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Range("E4").Copy Destination:=Range("A" & Emptyrow)
Range("F4").Copy Destination:=Range("B" & Emptyrow)
Range("G4").Copy Destination:=Range("C" & Emptyrow)
End Sub
Thanks in advance
PLEASE help me fix this, so it only writes in the next empty row and does not overwrites the data above.
My VBA-code is as following:
Sub Dagsopdatering()
Sheets("Dagens pris").Select
Range("A1:G1000").Clear
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://www.ok.dk/priser/benzin-olie-priser", Destination:=Range("$A$1"))
.Name = "benzin-olie-priser"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
Dim Emptyrow As Long
'Writes the date today'
Sheets("Priser").Select
Range("E4").Value = Date
Sheets("Info").Select
Range("G1").Value = Date
'Finds the first empty row in the column, and then copys into the first empty row'
Sheets("Priser").Select
Emptyrow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Range("E4").Copy Destination:=Range("A" & Emptyrow)
Range("F4").Copy Destination:=Range("B" & Emptyrow)
Range("G4").Copy Destination:=Range("C" & Emptyrow)
End Sub
Thanks in advance