Skip first 3 header rows - excel

I have a form that is currently allowing input from my form in VBA into my Excel spreadsheet. When I use the Previous button or the next button it deletes everything from a prior input into what is on the form. is there a way to Click previous and see the previous data entered, allow editting but change to the fields when you select the previous button again?
Public nCurrentRow As Long
Private Sub Next_Command_Click()
Do
nCurrentRow = nCurrentRow + 1
TraverseData (nCurrentRow)
Loop Until C_C_L.Cells(nCurrentRow, 1).Value = "" Or C_C_L.Cells(nCurrentRow, 1).Value = Me.PI_Text.Value
End Sub
Private Sub Previous_Command_Click()
Do
nCurrentRow = nCurrentRow - 1
TraverseData (nCurrentRow)
Loop Until nCurrentRow = 1 Or C_C_L.Cells(nCurrentRow, 1).Value = Me.PI_Text.Value
End Sub
Also Is there a way to skip the first 3 lines (headers) so the new data does not overwrite my headers?

You should add another button AddRecord_Command that will bring the set the current row to the next empty row. In this way, Previous_Command will move back one record and Next_Command will not move past the last record.
The code below should handle both this question and your previous question How to update spreadsheet from VBA Form?
Option Explicit
Private NC_C_L As Worksheet
Private nCurrentRow As Long
Private firstRow As Long
Private Sub UserForm_Initialize()
Set NC_C_L = Worksheets("Sheet1")
firstRow = 4
ReadData
End Sub
Private Sub AddRecord_Command_Click()
Dim lastRow As Long
lastRow = NC_C_L.Range("A" & NC_C_L.Rows.Count).End(xlUp).Row
WriteData
nCurrentRow = lastRow + 1
End Sub
Private Sub Next_Command_Click()
Dim lastRow As Long
lastRow = NC_C_L.Range("A" & NC_C_L.Rows.Count).End(xlUp).Row
If nCurrentRow < lastRow Then
WriteData
nCurrentRow = nCurrentRow + 1
ReadData
End If
End Sub
Private Sub Previous_Command_Click()
If nCurrentRow > firstRow Then
WriteData
nCurrentRow = nCurrentRow - 1
ReadData
End If
End Sub
Private Sub ReadData()
With NC_C_L
Me.A_Text.Value = .Cells(nCurrentRow, 1)
Me.B_Box = .Cells(nCurrentRow, 2)
Me.C_Combo.Value = .Cells(nCurrentRow, 3)
Me.C_Combo.Value = .Cells(nCurrentRow, 4)
Me.F_Combo.Value = .Cells(nCurrentRow, 5)
Me.H_Combo.Value = .Cells(nCurrentRow, 6)
Me.I_Combo.Value = .Cells(nCurrentRow, 7)
Me.J_Text.Value = .Cells(nCurrentRow, 8)
Me.K_Text.Value = .Cells(nCurrentRow, 9)
Me.Comments1_Text.Value = .Cells(nCurrentRow, 10)
Me.Comments2_Text.Value = .Cells(nCurrentRow, 11)
Me.Comments3_Text.Value = .Cells(nCurrentRow, 12)
Me.PhoneNumber_Text.Value = .Cells(nCurrentRow, 13)
Me.Address1_Text.Value = .Cells(nCurrentRow, 14)
Me.Address2_Text.Value = .Cells(nCurrentRow, 15)
Me.City_Text.Value = .Cells(nCurrentRow, 16)
Me.State_Combo.Value = .Cells(nCurrentRow, 17)
Me.Zip_Text.Value = .Cells(nCurrentRow, 18)
Me.EMail_Text.Value = .Cells(nCurrentRow, 19)
Me.P_Name_Text.Value = .Cells(nCurrentRow, 20)
Me.P_PhoneNumber_Text.Value = .Cells(nCurrentRow, 21)
Me.P_Address_Text.Value = .Cells(nCurrentRow, 22)
End With
End Sub
Private Sub WriteData()
With NC_C_L
.Cells(nCurrentRow, 1) = Me.A_Text.Value
.Cells(nCurrentRow, 2) = Me.B_Box
.Cells(nCurrentRow, 3) = Me.C_Combo.Value
.Cells(nCurrentRow, 4) = Me.C_Combo.Value
.Cells(nCurrentRow, 5) = Me.F_Combo.Value
.Cells(nCurrentRow, 6) = Me.H_Combo.Value
.Cells(nCurrentRow, 7) = Me.I_Combo.Value
.Cells(nCurrentRow, 8) = Me.J_Text.Value
.Cells(nCurrentRow, 9) = Me.K_Text.Value
.Cells(nCurrentRow, 10) = Me.Comments1_Text.Value
.Cells(nCurrentRow, 11) = Me.Comments2_Text.Value
.Cells(nCurrentRow, 12) = Me.Comments3_Text.Value
.Cells(nCurrentRow, 13) = Me.PhoneNumber_Text.Value
.Cells(nCurrentRow, 14) = Me.Address1_Text.Value
.Cells(nCurrentRow, 15) = Me.Address2_Text.Value
.Cells(nCurrentRow, 16) = Me.City_Text.Value
.Cells(nCurrentRow, 17) = Me.State_Combo.Value
.Cells(nCurrentRow, 18) = Me.Zip_Text.Value
.Cells(nCurrentRow, 19) = Me.EMail_Text.Value
.Cells(nCurrentRow, 20) = Me.P_Name_Text.Value
.Cells(nCurrentRow, 21) = Me.P_PhoneNumber_Text.Value
.Cells(nCurrentRow, 22) = Me.P_Address_Text.Value
End With
End Sub

Related

Copying data from List to UserForm VBA

I am wondering if anyone could help me with this. I have written vba code to achieve goal when i click on "Button1" macro button in my sheet1 to open userform2 with a searchbox(TextBox) one CommandButton and List in it.
I have divided the Problem into two Parts. One is working for me and the second one is not.
Problem 1 working:
Than in searchBox I will write some Name(characters) to do a search from existing sheet1 by clicking on SearchButton1. If it finds the data against that search(Name) than
Problem 2 not working:
I should be able to edit and save all the data stored against that Name in new userform I have created by the name of Userform33 having 15 TextBoxes and 2 commandButtons in it, one button for "Edit and save" and second for "close form".
Here is my code for userform2 that will show the data in the form of
List based on input in SearchBox
Code Problem 1 WORKING FINE:
> Option Explicit
>
> Private Sub TextBox1_Change() Me.TextBox1 =
> Format(StrConv(Me.TextBox1, vbLowerCase)) 'hier schreibt er nur noch
> klein
>
> Dim sh As Worksheet Set sh = Worksheets("LEADS DE") Dim i As Long Dim
> x As Long Dim p As Long Me.ListBox1.Clear
>
> 'For ListBox Header Me.ListBox1.AddItem "#"
> Me.ListBox1.List(ListBox1.ListCount - 1, 2) = leads.Cells(1, 6).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 3) = leads.Cells(1, 7).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 4) = leads.Cells(1, 19).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 5) = leads.Cells(1, 4).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 6) = leads.Cells(1, 21).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 7) = leads.Cells(1, 18).Value
>
>
>
> For i = 2 To sh.Range("B" & Rows.Count).End(xlUp).Row For x = 1 To
> Len(sh.Cells(i, 2)) p = Me.TextBox1.TextLength
>
> If LCase(Mid(sh.Cells(i, 6), x, p)) = Me.TextBox1 And Me.TextBox1 <>
> "" Then 'Mid(sh.Cells(i, 3 <-- die 3 zeigt wo gesucht werden soll
> With Me.ListBox1 .AddItem sh.Cells(i, 2) '.List(ListBox1.ListCount -
> 1, 1) = sh.Cells(i, 3) .List(ListBox1.ListCount - 1, 2) = sh.Cells(i,
> 6) .List(ListBox1.ListCount - 1, 3) = sh.Cells(i, 7)
> .List(ListBox1.ListCount - 1, 4) = sh.Cells(i, 19)
> .List(ListBox1.ListCount - 1, 5) = sh.Cells(i, 4)
> .List(ListBox1.ListCount - 1, 6) = sh.Cells(i, 21)
> .List(ListBox1.ListCount - 1, 7) = sh.Cells(i, 18)
>
> End With
>
>
> End If Next x Next i
>
>
> End Sub
>
>
> Private Sub UserForm_Initialize() Dim Zeile As Long
>
> Me.ListBox1.AddItem "#"
>
>
> Me.ListBox1.List(ListBox1.ListCount - 1, 1) = leads.Cells(1, 6).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 2) = leads.Cells(1, 7).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 3) = leads.Cells(1, 19).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 4) = leads.Cells(1, 4).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 5) = leads.Cells(1, 21).Value
> Me.ListBox1.List(ListBox1.ListCount - 1, 6) = leads.Cells(1, 18).Value
>
> For Zeile = 2 To leads.Cells(Rows.Count, 2).End(xlUp).Row
> Me.ListBox1.AddItem leads.Cells(Zeile, 2).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = leads.Cells(Zeile, 6).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = leads.Cells(Zeile, 7).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = leads.Cells(Zeile, 19).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = leads.Cells(Zeile, 4).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 5) = leads.Cells(Zeile, 21).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 6) = leads.Cells(Zeile, 18).Value
> Me.ListBox1.List(Me.ListBox1.ListCount - 1, 7) = leads.Cells(Zeile, 18).Row
> Next Zeile
> End Sub
Well above code is working fine!!!
Now Code for Problem 2 which is Not Working for Me!
Private Sub CommandButton1_Click()
Dim check_data As Characters
check_data = Sheets("LEADS DE").Range("F")
If check_data = UserForm2.TextBox1 Then
UserForm33.TextBox1 = Sheets("LEADS DE").Range("B")
UserForm33.TextBox5 = Sheets("LEADS DE").Range("F")
UserForm33.TextBox8 = Sheets("LEADS DE").Range("I")
UserForm33.TextBox9 = Sheets("LEADS DE").Range("J")
UserForm33.TextBox6 = Sheets("LEADS DE").Range("G")
UserForm33.TextBox7 = Sheets("LEADS DE").Range("H")
UserForm33.TextBox10 = Sheets("LEADS DE").Range("K")
UserForm33.TextBox11 = Sheets("LEADS DE").Range("L")
UserForm33.TextBox14 = Sheets("LEADS DE").Range("D")
UserForm33.TextBox12 = Sheets("LEADS DE").Range("N")
UserForm33.TextBox15 = Sheets("LEADS DE").Range("O")
UserForm33.TextBox4 = Sheets("LEADS DE").Range("M")
UserForm33.TextBox16 = Sheets("LEADS DE").Range("P")
UserForm33.TextBox17 = Sheets("LEADS DE").Range("Q")
UserForm33.TextBox18 = Sheets("LEADS DE").Range("R")
UserForm33.Show
End If
End Sub
Main Problem:
I am stuck in Problem 2 and not able to show the data that comes from search in the form of List into newly created UserForm33 and than " edit(update) and save data " on the same userform33.
Any help is very appreciated from Experts.
Thanks,
Add another column to the Listbox and use column 0 to store the row number for the record. You can set column width to 0 to hide. Add a label to the UserForm33 to store the row number on the spreadsheet that is being edited.
UserForm2 code
Option Explicit
Private Sub CommandButton1_Click() ' Edit
Dim i As Long, r As Long
With ListBox1
i = .ListIndex ' selected row
If i < 1 Then Exit Sub
r = .List(i, 0) ' source row from sheet
End With
Call UserForm33.LoadForm(r)
End Sub
Private Sub TextBox1_Change()
Me.TextBox1 = Format(StrConv(Me.TextBox1, vbLowerCase)) 'hier schreibt er nur noch klein
Me.ListBox1.Clear
Call FillListbox(Me.TextBox1.Text)
End Sub
Private Sub UserForm_Initialize()
Call FillListbox("")
'ListBox1.ColumnWidths = "0" hide
End Sub
Private Sub FillListbox(s As String)
Dim Zeile As Long, Lastrow As Long, i As Long, c As Long
Dim ws As Worksheet, ar
ar = Array("B", "F", "G", "S", "D", "U", "R")
Set ws = Sheets("LEADS DE")
Lastrow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row
With Me.ListBox1
For Zeile = 1 To Lastrow
If Zeile = 1 Or s = "" _
Or LCase(ws.Cells(Zeile, "F")) Like "*" & s & "*" Then
.AddItem "#"
i = .ListCount - 1
.List(i, 0) = Zeile
For c = 0 To UBound(ar)
.List(i, c + 1) = ws.Cells(Zeile, ar(c))
Next
End If
Next
.List(0, 1) = "#"
End With
End Sub
UserForm33 code
Option Explicit
Private Sub CommandButton1_Click() ' Save
Call SaveForm
End Sub
Sub LoadForm(r As Long)
Dim ws As Worksheet, arBox, arCol, i As Long
arBox = Split("1,5,8,9,6,7,10,11,14,12,15,4,16,17,18", ",")
arCol = Split("B,F,I,J,G,H,K,L,D,N,O,M,P,Q,R", ",")
Set ws = Sheets("LEADS DE")
With Me
.Label1 = r
For i = 0 To UBound(arBox)
.Controls("TextBox" & arBox(i)) = ws.Cells(r, arCol(i))
Next
.Show
End With
End Sub
Sub SaveForm()
Dim ws As Worksheet, arBox, arCol, i As Long, r As Long
arBox = Split("1,5,8,9,6,7,10,11,14,12,15,4,16,17,18", ",")
arCol = Split("B,F,I,J,G,H,K,L,D,N,O,M,P,Q,R", ",")
Set ws = Sheets("LEADS DE")
With Me
r = .Label1
For i = 0 To UBound(arBox)
ws.Cells(r, arCol(i)) = .Controls("TextBox" & arBox(i))
Next
End With
End Sub

Userform opens when selecting command button. How do I make data input into the textboxes in the form insert onto row in separate sheet?

I'm trying to create a UserForm which will open when I select a command button. The purpose of it is to capture data from a selected row concerning a "tour" - i.e. the tour code, start date and end date, and then for me to "split" the tour, for which I need to enter new tour codes, start dates and end dates.
I need the data from the form to go into a separate sheet (called "splits"), so that I have a record of the original tour details, and the new tour details in one sheet. But I get a Run-Time error '1004' (Application-defined or object-defined error) when I try to run the macro. I'm new to VBA and I don't know what I've done wrong!
This is my code so far:
Private Sub UserForm_Initialize()
With Me
.OriginalTourCode.Value = Cells(ActiveCell.Row, "A").Value
.OriginalStartDate.Value = Cells(ActiveCell.Row, "B").Value
.OriginalEndDate.Value = Cells(ActiveCell.Row, "C").Value
End With
End Sub
Private Sub SplitTourCommand_Click()
Dim ctrl As Control
Dim ws As Worksheet
Set ws = Sheets("Splits")
erow = ws.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0)
Cells(erow, 1) = OriginalTourCode.Text
Cells(erow, 2) = OriginalStartDate.Text
Cells(erow, 3) = OriginalEndDate.Text
Cells(erow, 4) = NewTourCode1.Text
Cells(erow, 5) = NewStartDate1.Text
Cells(erow, 6) = NewEndDate1.Text
Cells(erow, 7) = NewTourCode2.Text
Cells(erow, 8) = NewStartDate2.Text
Cells(erow, 9) = NewEndDate2.Text
Cells(erow, 10) = ReasonForSplit.Text
End Sub
Private Sub CloseCommand_Click()
Unload Me
End Sub
The Userform Intitialise section automatically fills in the first three cells of the UserForm, and then I'll use the form to enter the new data.
The Close command section is just a separate button on the form to exit out.
How to I get the form, when I click the "split tour" command button, to enter the data into the next empty row of the "splits" sheet?
Thanks so much in advance for helping.
erow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
There were 2 errors in your code. First, the command is xlUp, not x1Up - "xl" is short for "Excel", not "X One" - this is a perfect example of why you should almost always use Option Explicit
Second: your code as-is will try to put the .Value from the cell into untyped variable erow - since the cell is blank (as the cell below the last cell with data), this means that erow will always be 0. And Row 0 does not exist to put data into.
Instead, by using Range.Row, we get the next row number to insert data on
You were so close
Dim ctrl As Control
Dim ws As Worksheet
Set ws = Sheets("Splits")
erow = ws.Cells(Rows.Count, 1).End(x1Up).Offset(1, 0)
ws.Cells(erow, 1) = OriginalTourCode.Text
ws.Cells(erow, 2) = OriginalStartDate.Text
ws.Cells(erow, 3) = OriginalEndDate.Text
ws.Cells(erow, 4) = NewTourCode1.Text
ws.Cells(erow, 5) = NewStartDate1.Text
ws.Cells(erow, 6) = NewEndDate1.Text
ws.Cells(erow, 7) = NewTourCode2.Text
ws.Cells(erow, 8) = NewStartDate2.Text
ws.Cells(erow, 9) = NewEndDate2.Text
ws.Cells(erow, 10) = ReasonForSplit.Text
End Sub
No Object Variable Necessary
The End Parameter is xlUp not x1Up.
Array Version
Option Explicit
Private Sub SplitTourCommand_Click()
Const cSheet As String = "Splits"
Dim erow As Long
Dim vnt As Variant
ReDim vnt(1 To 1, 1 To 10) As String
vnt(1, 1) = OriginalTourCode.Text
vnt(1, 2) = OriginalStartDate.Text
vnt(1, 3) = OriginalEndDate.Text
vnt(1, 4) = NewTourCode1.Text
vnt(1, 5) = NewStartDate1.Text
vnt(1, 6) = NewEndDate1.Text
vnt(1, 7) = NewTourCode2.Text
vnt(1, 8) = NewStartDate2.Text
vnt(1, 9) = NewEndDate2.Text
vnt(1, 10) = ReasonForSplit.Text
With Worksheets(cSheet)
erow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
.Cells(erow, 1).Resize(, 10) = vnt
End With
End Sub
Range Version
Option Explicit
Private Sub SplitTourCommand_Click()
Const cSheet As String = "Splits"
Dim erow As Long
With Worksheets(cSheet)
erow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1
.Cells(erow, 1) = OriginalTourCode.Text
.Cells(erow, 2) = OriginalStartDate.Text
.Cells(erow, 3) = OriginalEndDate.Text
.Cells(erow, 4) = NewTourCode1.Text
.Cells(erow, 5) = NewStartDate1.Text
.Cells(erow, 6) = NewEndDate1.Text
.Cells(erow, 7) = NewTourCode2.Text
.Cells(erow, 8) = NewStartDate2.Text
.Cells(erow, 9) = NewEndDate2.Text
.Cells(erow, 10) = ReasonForSplit.Text
End With
End Sub

Mismatch error/ code not working

This is the updated code. I am getting a mismatch error now. It would be great if someone could offer some help. Thanks in advance!
Sub Macro2()
Dim rowcount As Long
Dim target As Variant, startcell4 As Range
Set startcell4 = ActiveSheet.Cells(2, 1)
rowcount = Range(Range("E2"), Range("E2").End(xlDown)).Rows.Count
For i = 2 To rowcount + 1
If Not ActiveSheet.Cells(i, 26) = ActiveSheet.Cells(i + 1, 26) Then
Set target = Application.Match(ActiveSheet.Cells(i, 26), Worksheets(19).Range("A6:A3000"), 0)
If Not IsError(target) Then
ActiveSheet.startcell4.Offset(0, 17).Value = Worksheets(19).Cells(target + 6, 10)
Set startcell4 = ActiveSheet.Cells(i + 1, 26)
End If
End If
Next i
End Sub
Changed:
"Set target = ..." to "target = ..."
"ActiveSheet.startcell4" to "startcell4"
A little refactoring
Coming to this
Sub Macro2()
Dim rowcount As Long
Dim target As Variant, startcell4 As Range
Set startcell4 = Cells(2, 1)
rowcount = Range("E2").End(xlDown).Row
For i = 2 To rowcount
If Not Cells(i, 26) = Cells(i + 1, 26) Then
target = Application.Match(Cells(i, 26), Worksheets(19).Range("A6:A3000"), 0)
If Not IsError(target) Then
startcell4.Offset(0, 17).Value = Worksheets(19).Cells(target + 6, 10)
Set startcell4 = Cells(i + 1, 26)
End If
End If
Next i
End Sub

Excel Sharing sheet with vba and working buttons

I'm trying to share a sheet with a button that open a new window(made in vb) but when I share it the button that guides to another window lock simple doesn't work (yes I unchecked lock), theres something I need to do to share that button and the another window?
The work of this windows is to edit cells.
Here's the code from the window, there's:
private Sub CommandButton1_Click()
Dim i, a, b, c, d
Dim prio As String
i = CInt(Sheets("Sheet1").Cells(6, 17))
a = CInt(Sheets("Sheet1").Cells(7, 17))
Sheets("Sheet1").Cells(i, 1) = a
Sheets("Sheet1").Cells(i, 2) = Peca.Text
Sheets("Sheet1").Cells(i, 3) = Qt.Text
Sheets("Sheet1").Cells(i, 4) = ComboBox1.Value
Sheets("Sheet1").Cells(i, 5) = Responsavel.Text
Sheets("Sheet1").Cells(i, 6) = Cliente.Text
Sheets("Sheet1").Cells(i, 7) = Maquina.Text
Sheets("Sheet1").Cells(i, 8) = NumSerie.Text
Sheets("Sheet1").Cells(i, 9) = Modelo.Text
Sheets("Sheet1").Cells(i, 10) = Obser.Text
Sheets("Sheet1").Cells(6, 17) = CInt(Sheets("Sheet1").Cells(6, 17)) + 1
Sheets("Sheet1").Cells(7, 17) = CInt(Sheets("Sheet1").Cells(7, 17)) + 1
Peca.Text = ""
Qt.Text = ""
ComboBox1.Value = ""
Responsavel.Text = ""
Cliente.Text = ""
Maquina.Text = ""
NumSerie.Text = ""
Modelo.Text = ""
Obser.Text = ""
End Sub
Private Sub CommandButton2_Click()
Sheets("Sheet1").Cells(12, 15) = Cliente.Text
End Sub
Private Sub CommandButton3_Click()
Sheets("Sheet1").Cells(12, 15) = Maquina.Text
Sheets("Sheet1").Cells(13, 15) = NumSerie.Text
Sheets("Sheet1").Cells(14, 15) = Modelo.Text
End Sub
Private Sub CommandButton4_Click()
Cliente.Text = Sheets("Sheet1").Cells(12, 15)
End Sub
Private Sub CommandButton5_Click()
Maquina.Text = Sheets("Sheet1").Cells(12, 15)
NumSerie.Text = Sheets("Sheet1").Cells(13, 15)
Modelo.Text = Sheets("Sheet1").Cells(14, 15)
End Sub

Find next empty row for automatic data entry from excel userform

Private Sub CommandButton1_Click()
NextRow = 2
Sheets("data").Cells(NextRow, 2) = Now
Sheets("data").Cells(NextRow, 3) = Sheets("sheet1").Cells(NextRow, 2)
Sheets("data").Cells(NextRow, 4) = ThisWorkbook.Sheets("Sheet1").Range("b3")
Sheets("data").Cells(NextRow, 5) = ThisWorkbook.Sheets("Sheet1").Range("b4")
Sheets("data").Cells(NextRow, 6) = ThisWorkbook.Sheets("Sheet1").Range("b5")
Sheets("data").Cells(NextRow, 7) = ThisWorkbook.Sheets("Sheet1").Range("b6")
Sheets("data").Cells(NextRow, 8) = ThisWorkbook.Sheets("Sheet1").Range("b7")
Sheets("data").Cells(NextRow, 9) = ThisWorkbook.Sheets("Sheet1").Range("b8")
Sheets("data").Cells(NextRow, 10) = ThisWorkbook.Sheets("Sheet1").Range("b10")
Sheets("data").Cells(NextRow, 11) = ThisWorkbook.Sheets("Sheet1").Range("b11")
Sheets("data").Cells(NextRow, 12) = ThisWorkbook.Sheets("Sheet1").Range("b12")
End Sub
Here is my code. Whenever I keep on giving value it overrides. How to change it? How to make entry in seperate row?
You could pop a little loop in to discover the next empty row, for example (untested!):
NextRow=2
do until Sheets("data").Cells(NextRow,2) = ""
NextRow = NextRow + 1
Loop

Resources